Advertisement
xerpi

SceBt test Vita

Nov 13th, 2016
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.23 KB | None | 0 0
  1. /*
  2.  * Bluetooth test by xerpi
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <psp2/ctrl.h>
  7. #include "debugScreen.h"
  8.  
  9. #define printf(...) psvDebugScreenPrintf(__VA_ARGS__)
  10.  
  11. static void wait_key_press();
  12.  
  13. #define TEST_CALL(f, ...) \
  14.     printf(# f " returned 0x%08X\n", f(__VA_ARGS__))
  15.  
  16. static void print_mac(unsigned char mac[5])
  17. {
  18.     printf("%02X", mac[4]);
  19.     for (int i = 4; i >= 0; i--)
  20.         printf(":%02X", mac[i]);
  21. }
  22.  
  23. int sceRegMgrGetKeyInt(const char*, const char*, int*);
  24. int sceRegMgrGetKeyStr(const char*, const char*, char*, unsigned short size);
  25. int sceRegMgrGetKeyBin(const char*, const char*, unsigned char*, unsigned short size);
  26. int sceRegMgrSetKeyInt(const char*, const char*, int);
  27. int sceRegMgrSetKeyStr(const char*, const char*, const char*, unsigned short size);
  28. int sceRegMgrSetKeyBin(const char*, const char*, const unsigned char*, unsigned short size);
  29.  
  30. int sceWlanGetConfiguration(int r0, int r1, int r2, int r3);
  31. int sceWlanGetWakeOnTargetProcess(int r0, int r1, int r2, int r3);
  32. int sceWlanRegisterCallback(int r0, int r1, int r2, int r3);
  33. int sceWlanSetConfiguration(int r0, int r1, int r2, int r3);
  34. int sceWlanUnregisterCallback(int r0, int r1, int r2, int r3);
  35.  
  36. #define SCE_BT_ERROR_CB_OVERFLOW 0x802f0c04
  37.  
  38. typedef struct {
  39.     unsigned char mac[5];
  40.     unsigned char unk1[32 - 5];
  41.     char name[128];
  42.     unsigned char unk2[128];
  43. } SceBtRegisteredInfo;
  44.  
  45. typedef struct {
  46.     unsigned char data[0x10];
  47. } SceBtEvent;
  48.  
  49. int sceBtAvrcpReadVolume(int r0, int r1, int r2, int r3);
  50. int sceBtAvrcpSendButton(int r0, int r1, int r2, int r3);
  51. int sceBtAvrcpSendVolume(int r0, int r1, int r2, int r3);
  52. int sceBtAvrcpSetPlayStatus(int r0, int r1, int r2, int r3);
  53. int sceBtAvrcpSetTitle(int r0, int r1, int r2, int r3);
  54. int sceBtDeleteRegisteredInfo(int r0, int r1, int r2, int r3);
  55. int sceBtFreqAudio(int r0, int r1, int r2, int r3);
  56. int sceBtGetConfiguration(void); // returns 0x0 BT disabled, 0x9 if enabled
  57. int sceBtGetConnectingInfo(int r0, int r1, int r2, int r3);
  58. int sceBtGetDeviceName(int r0, int r1, char *name, int name_len);
  59. int sceBtGetInfoForTest(int r0, int r1, int r2, int r3);
  60. int sceBtGetLastError(void);
  61. int sceBtGetRegisteredInfo(int device, int unk, SceBtRegisteredInfo *info, unsigned int info_size);
  62. int sceBtGetStatusForTest(int r0, int r1, int r2, int r3);
  63. int sceBtHfpGetCurrentPhoneNumber(int r0, int r1, int r2, int r3);
  64. int sceBtHfpRequest(int r0, int r1, int r2, int r3);
  65. int sceBtHidGetReportDescriptor(int r0, int r1, int r2, int r3);
  66. int sceBtHidTransfer(int r0, int r1, int r2, int r3);
  67. int sceBtPairingOOB(int r0, int r1, int r2, int r3);
  68. int sceBtPushBip(int r0, int r1, int r2, int r3);
  69. int sceBtPushOpp(int r0, int r1, int r2, int r3);
  70. int sceBtReadEvent(SceBtEvent *events, int num_events);
  71. int sceBtRecvAudio(int r0, int r1, int r2, int r3);
  72. int sceBtRecvBip(int r0, int r1, int r2, int r3);
  73. int sceBtRecvOpp(int r0, int r1, int r2, int r3);
  74. int sceBtRecvSpp(int r0, int r1, int r2, int r3);
  75. int sceBtRegisterCallback(SceUID cb, int unused, int flags1, int flags2);
  76. int sceBtReplyPinCode(int r0, int r1, int r2, int r3);
  77. int sceBtReplyUserConfirmation(int r0, int r1, int r2, int r3);
  78. int sceBtSendAudio(int r0, int r1, int r2, int r3);
  79. int sceBtSendL2capEchoRequestForTest(int r0, int r1, int r2, int r3);
  80. int sceBtSendSpp(int r0, int r1, int r2, int r3);
  81. int sceBtSetConfiguration(int r0); //0 = disable bt, 1 = enabling, 2 = enabled 3 = disabling?
  82. int sceBtSetContentProtection(int r0);
  83. int sceBtSetInquiryResultForTest(unsigned char *);
  84. int sceBtSetInquiryScan(int r0);
  85. int sceBtSetL2capEchoResponseBufferForTest(int r0, int r1, int r2, int r3);
  86. int sceBtSetStatusForTest(int r0, int r1, int r2, int r3);
  87. int sceBtStartAudio(int r0, int r1, int r2, int r3);
  88. int sceBtStartConnect(int r0, int r1); // r0 = dev index
  89. int sceBtStartDisconnect(int r0, int r1, int r2, int r3);
  90. int sceBtStartInquiry(void);
  91. int sceBtStopAudio(int r0, int r1, int r2, int r3);
  92. int sceBtStopInquiry(void);
  93. int sceBtUnregisterCallback(int r0, int r1, int r2, int r3);
  94.  
  95. typedef void (*SceBtCallback)(int r0, int r1, int r2, int r3);
  96.  
  97. /*static int wlan_cb_func(int notifyId, int notifyCount, int notifyArg, void *common)
  98. {
  99.     printf("WLAN callback called!: 0x%08X 0x%08X 0x%08X %p\n", notifyId, notifyCount, notifyArg, common);
  100.  
  101.     return 0;
  102. }*/
  103.  
  104. static int bt_cb_func(int notifyId, int notifyCount, int notifyArg, void *common)
  105. {
  106.     printf("BT CB: 0x%08X 0x%08X 0x%08X %p\n", notifyId, notifyCount, notifyArg, common);
  107.  
  108.     /*
  109.      * Request connection: 09 0F
  110.      * Connect: 01 D2
  111.      * Disconnect: 06 16 (one time 01 D1)
  112.      *
  113.      * [0] = Event type, (HID valid ones: 0x5, 0x6, 0xA, 0xB, 0xC)
  114.      *
  115.      * 0x002508 = Game controller class
  116.      * 0x200404 = Audio device class
  117.      */
  118.  
  119.     while (1) {
  120.         SceBtEvent ev = {0};
  121.         int ret;
  122.         do {
  123.             ret = sceBtReadEvent(&ev, 1);
  124.         } while (ret == SCE_BT_ERROR_CB_OVERFLOW);
  125.  
  126.         if (ret <= 0)
  127.             break;
  128.  
  129.         //TEST_CALL(sceBtReplyPinCode, 0, 0, 0, 0);
  130.  
  131.         printf("Read %d event(s)!\n", ret);
  132.  
  133.         for (int i = 0; i < 0x10; i++)
  134.             printf(" %02X", ev.data[i]);
  135.  
  136.         printf("\n");
  137.     }
  138.  
  139.     return 0;
  140. }
  141.  
  142. int main(int argc, char *argv[])
  143. {
  144.     //SceUID wlan_cb;
  145.     SceUID bt_cb;
  146.  
  147.     psvDebugScreenInit();
  148.  
  149.     printf("BT test by xerpi\n\n");
  150.  
  151.     /*wlan_cb = sceKernelCreateCallback("wlan_cb", 0, wlan_cb_func, NULL);
  152.     printf("WLAN CB UID: 0x%08X\n", wlan_cb);
  153.     TEST_CALL(sceWlanRegisterCallback, wlan_cb, 0, 0, 0);*/
  154.  
  155.     bt_cb = sceKernelCreateCallback("bt_cb", 0, bt_cb_func, NULL);
  156.     printf("BT CB UID: 0x%08X\n", bt_cb);
  157.     TEST_CALL(sceBtRegisterCallback, bt_cb, 0, 0x060E4B, 0x0607F1);
  158.  
  159.     SceBtRegisteredInfo btinfo;
  160.     TEST_CALL(sceBtGetRegisteredInfo, 0, 0, &btinfo, sizeof(btinfo));
  161.  
  162.     printf("    Name: %s\n", btinfo.name);
  163.     printf("    MAC: "); print_mac(btinfo.mac); printf("\n");
  164.  
  165.  
  166.     printf("\n");
  167.  
  168.     TEST_CALL(sceBtSetContentProtection, 0);
  169.  
  170.     //TEST_CALL(sceBtSetConfiguration, 3);
  171.  
  172.     /*TEST_CALL(sceBtSetInquiryScan, 1);
  173.     TEST_CALL(sceBtStartInquiry);
  174.     sceKernelDelayThreadCB(4 * 1000 * 1000);
  175.     TEST_CALL(sceBtStopInquiry);*/
  176.  
  177.  
  178.     /*while (1) {
  179.         int val1 = 0, val2 = 0;
  180.         TEST_CALL(sceBtGetConfiguration, &val1, &val2, 0, 0);
  181.         printf(" val1: 0x%08X val2: 0x%08X\n", val1, val2);
  182.         sceKernelDelayThread(500 * 1000);
  183.     }*/
  184.  
  185.     /*TEST_CALL(sceBtSetConfiguration, 1, 0, 0, 0);
  186.     TEST_CALL(sceBtHidTransfer, 0, 0, 0, 0);
  187.     TEST_CALL(sceBtSetInquiryScan, 0, 0, 0, 0);
  188.     TEST_CALL(sceBtStartInquiry, 0, 0, 0, 0);
  189.     TEST_CALL(sceBtGetConnectingInfo, 0, 0, 0, 0);
  190.     TEST_CALL(sceBtReadEvent, 0, 0, 0, 0);*/
  191.  
  192.     wait_key_press();
  193.  
  194.     return 0;
  195. }
  196.  
  197. /*void bt_reg_test()
  198. {
  199.     int bt_enable;
  200.     TEST_CALL(sceRegMgrGetKeyInt, "/CONFIG/BT", "bt_enable", &bt_enable);
  201.     printf("bt_enable: %d\n", bt_enable);
  202.  
  203.     int bt_mic;
  204.     TEST_CALL(sceRegMgrGetKeyInt, "/CONFIG/BT", "bt_mic", &bt_mic);
  205.     printf("bt_mic: %d\n", bt_mic);
  206.  
  207.     for (int j = 0; j < 0x10; j++) {
  208.         char db[64];
  209.         snprintf(db, sizeof(db), "/CONFIG/BT/%02d", j);
  210.  
  211.         unsigned char info[0x788];
  212.         TEST_CALL(sceRegMgrGetKeyBin, db, "info", info, sizeof(info));
  213.         for (int i = 0; i < 16; i++)
  214.             printf(" %02X", info[i]);
  215.         printf("\n");
  216.     }
  217. }*/
  218.  
  219. void wait_key_press()
  220. {
  221.     SceCtrlData pad;
  222.  
  223.     printf("\nPress X to continue.\n");
  224.  
  225.     while (1) {
  226.         sceCtrlPeekBufferPositive(0, &pad, 1);
  227.         if (pad.buttons & SCE_CTRL_CROSS)
  228.             break;
  229.         sceKernelDelayThreadCB(100 * 1000);
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement