Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Bluetooth test by xerpi
- */
- #include <stdio.h>
- #include <psp2/ctrl.h>
- #include "debugScreen.h"
- #define printf(...) psvDebugScreenPrintf(__VA_ARGS__)
- static void wait_key_press();
- #define TEST_CALL(f, ...) \
- printf(# f " returned 0x%08X\n", f(__VA_ARGS__))
- static void print_mac(unsigned char mac[5])
- {
- printf("%02X", mac[4]);
- for (int i = 4; i >= 0; i--)
- printf(":%02X", mac[i]);
- }
- int sceRegMgrGetKeyInt(const char*, const char*, int*);
- int sceRegMgrGetKeyStr(const char*, const char*, char*, unsigned short size);
- int sceRegMgrGetKeyBin(const char*, const char*, unsigned char*, unsigned short size);
- int sceRegMgrSetKeyInt(const char*, const char*, int);
- int sceRegMgrSetKeyStr(const char*, const char*, const char*, unsigned short size);
- int sceRegMgrSetKeyBin(const char*, const char*, const unsigned char*, unsigned short size);
- int sceWlanGetConfiguration(int r0, int r1, int r2, int r3);
- int sceWlanGetWakeOnTargetProcess(int r0, int r1, int r2, int r3);
- int sceWlanRegisterCallback(int r0, int r1, int r2, int r3);
- int sceWlanSetConfiguration(int r0, int r1, int r2, int r3);
- int sceWlanUnregisterCallback(int r0, int r1, int r2, int r3);
- #define SCE_BT_ERROR_CB_OVERFLOW 0x802f0c04
- typedef struct {
- unsigned char mac[5];
- unsigned char unk1[32 - 5];
- char name[128];
- unsigned char unk2[128];
- } SceBtRegisteredInfo;
- typedef struct {
- unsigned char data[0x10];
- } SceBtEvent;
- int sceBtAvrcpReadVolume(int r0, int r1, int r2, int r3);
- int sceBtAvrcpSendButton(int r0, int r1, int r2, int r3);
- int sceBtAvrcpSendVolume(int r0, int r1, int r2, int r3);
- int sceBtAvrcpSetPlayStatus(int r0, int r1, int r2, int r3);
- int sceBtAvrcpSetTitle(int r0, int r1, int r2, int r3);
- int sceBtDeleteRegisteredInfo(int r0, int r1, int r2, int r3);
- int sceBtFreqAudio(int r0, int r1, int r2, int r3);
- int sceBtGetConfiguration(void); // returns 0x0 BT disabled, 0x9 if enabled
- int sceBtGetConnectingInfo(int r0, int r1, int r2, int r3);
- int sceBtGetDeviceName(int r0, int r1, char *name, int name_len);
- int sceBtGetInfoForTest(int r0, int r1, int r2, int r3);
- int sceBtGetLastError(void);
- int sceBtGetRegisteredInfo(int device, int unk, SceBtRegisteredInfo *info, unsigned int info_size);
- int sceBtGetStatusForTest(int r0, int r1, int r2, int r3);
- int sceBtHfpGetCurrentPhoneNumber(int r0, int r1, int r2, int r3);
- int sceBtHfpRequest(int r0, int r1, int r2, int r3);
- int sceBtHidGetReportDescriptor(int r0, int r1, int r2, int r3);
- int sceBtHidTransfer(int r0, int r1, int r2, int r3);
- int sceBtPairingOOB(int r0, int r1, int r2, int r3);
- int sceBtPushBip(int r0, int r1, int r2, int r3);
- int sceBtPushOpp(int r0, int r1, int r2, int r3);
- int sceBtReadEvent(SceBtEvent *events, int num_events);
- int sceBtRecvAudio(int r0, int r1, int r2, int r3);
- int sceBtRecvBip(int r0, int r1, int r2, int r3);
- int sceBtRecvOpp(int r0, int r1, int r2, int r3);
- int sceBtRecvSpp(int r0, int r1, int r2, int r3);
- int sceBtRegisterCallback(SceUID cb, int unused, int flags1, int flags2);
- int sceBtReplyPinCode(int r0, int r1, int r2, int r3);
- int sceBtReplyUserConfirmation(int r0, int r1, int r2, int r3);
- int sceBtSendAudio(int r0, int r1, int r2, int r3);
- int sceBtSendL2capEchoRequestForTest(int r0, int r1, int r2, int r3);
- int sceBtSendSpp(int r0, int r1, int r2, int r3);
- int sceBtSetConfiguration(int r0); //0 = disable bt, 1 = enabling, 2 = enabled 3 = disabling?
- int sceBtSetContentProtection(int r0);
- int sceBtSetInquiryResultForTest(unsigned char *);
- int sceBtSetInquiryScan(int r0);
- int sceBtSetL2capEchoResponseBufferForTest(int r0, int r1, int r2, int r3);
- int sceBtSetStatusForTest(int r0, int r1, int r2, int r3);
- int sceBtStartAudio(int r0, int r1, int r2, int r3);
- int sceBtStartConnect(int r0, int r1); // r0 = dev index
- int sceBtStartDisconnect(int r0, int r1, int r2, int r3);
- int sceBtStartInquiry(void);
- int sceBtStopAudio(int r0, int r1, int r2, int r3);
- int sceBtStopInquiry(void);
- int sceBtUnregisterCallback(int r0, int r1, int r2, int r3);
- typedef void (*SceBtCallback)(int r0, int r1, int r2, int r3);
- /*static int wlan_cb_func(int notifyId, int notifyCount, int notifyArg, void *common)
- {
- printf("WLAN callback called!: 0x%08X 0x%08X 0x%08X %p\n", notifyId, notifyCount, notifyArg, common);
- return 0;
- }*/
- static int bt_cb_func(int notifyId, int notifyCount, int notifyArg, void *common)
- {
- printf("BT CB: 0x%08X 0x%08X 0x%08X %p\n", notifyId, notifyCount, notifyArg, common);
- /*
- * Request connection: 09 0F
- * Connect: 01 D2
- * Disconnect: 06 16 (one time 01 D1)
- *
- * [0] = Event type, (HID valid ones: 0x5, 0x6, 0xA, 0xB, 0xC)
- *
- * 0x002508 = Game controller class
- * 0x200404 = Audio device class
- */
- while (1) {
- SceBtEvent ev = {0};
- int ret;
- do {
- ret = sceBtReadEvent(&ev, 1);
- } while (ret == SCE_BT_ERROR_CB_OVERFLOW);
- if (ret <= 0)
- break;
- //TEST_CALL(sceBtReplyPinCode, 0, 0, 0, 0);
- printf("Read %d event(s)!\n", ret);
- for (int i = 0; i < 0x10; i++)
- printf(" %02X", ev.data[i]);
- printf("\n");
- }
- return 0;
- }
- int main(int argc, char *argv[])
- {
- //SceUID wlan_cb;
- SceUID bt_cb;
- psvDebugScreenInit();
- printf("BT test by xerpi\n\n");
- /*wlan_cb = sceKernelCreateCallback("wlan_cb", 0, wlan_cb_func, NULL);
- printf("WLAN CB UID: 0x%08X\n", wlan_cb);
- TEST_CALL(sceWlanRegisterCallback, wlan_cb, 0, 0, 0);*/
- bt_cb = sceKernelCreateCallback("bt_cb", 0, bt_cb_func, NULL);
- printf("BT CB UID: 0x%08X\n", bt_cb);
- TEST_CALL(sceBtRegisterCallback, bt_cb, 0, 0x060E4B, 0x0607F1);
- SceBtRegisteredInfo btinfo;
- TEST_CALL(sceBtGetRegisteredInfo, 0, 0, &btinfo, sizeof(btinfo));
- printf(" Name: %s\n", btinfo.name);
- printf(" MAC: "); print_mac(btinfo.mac); printf("\n");
- printf("\n");
- TEST_CALL(sceBtSetContentProtection, 0);
- //TEST_CALL(sceBtSetConfiguration, 3);
- /*TEST_CALL(sceBtSetInquiryScan, 1);
- TEST_CALL(sceBtStartInquiry);
- sceKernelDelayThreadCB(4 * 1000 * 1000);
- TEST_CALL(sceBtStopInquiry);*/
- /*while (1) {
- int val1 = 0, val2 = 0;
- TEST_CALL(sceBtGetConfiguration, &val1, &val2, 0, 0);
- printf(" val1: 0x%08X val2: 0x%08X\n", val1, val2);
- sceKernelDelayThread(500 * 1000);
- }*/
- /*TEST_CALL(sceBtSetConfiguration, 1, 0, 0, 0);
- TEST_CALL(sceBtHidTransfer, 0, 0, 0, 0);
- TEST_CALL(sceBtSetInquiryScan, 0, 0, 0, 0);
- TEST_CALL(sceBtStartInquiry, 0, 0, 0, 0);
- TEST_CALL(sceBtGetConnectingInfo, 0, 0, 0, 0);
- TEST_CALL(sceBtReadEvent, 0, 0, 0, 0);*/
- wait_key_press();
- return 0;
- }
- /*void bt_reg_test()
- {
- int bt_enable;
- TEST_CALL(sceRegMgrGetKeyInt, "/CONFIG/BT", "bt_enable", &bt_enable);
- printf("bt_enable: %d\n", bt_enable);
- int bt_mic;
- TEST_CALL(sceRegMgrGetKeyInt, "/CONFIG/BT", "bt_mic", &bt_mic);
- printf("bt_mic: %d\n", bt_mic);
- for (int j = 0; j < 0x10; j++) {
- char db[64];
- snprintf(db, sizeof(db), "/CONFIG/BT/%02d", j);
- unsigned char info[0x788];
- TEST_CALL(sceRegMgrGetKeyBin, db, "info", info, sizeof(info));
- for (int i = 0; i < 16; i++)
- printf(" %02X", info[i]);
- printf("\n");
- }
- }*/
- void wait_key_press()
- {
- SceCtrlData pad;
- printf("\nPress X to continue.\n");
- while (1) {
- sceCtrlPeekBufferPositive(0, &pad, 1);
- if (pad.buttons & SCE_CTRL_CROSS)
- break;
- sceKernelDelayThreadCB(100 * 1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement