📄 opttest.cxx
字号:
continue;
}
if (wcsicmp (szCommand, L"ENCRYPT OFF") == 0) {
int e = FALSE;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_ENCRYPT, (char *)&e, sizeof(e)));
continue;
}
if (wcsicmp (szCommand, L"GETMODE") == 0) {
int mode = -1;
int isize = sizeof(mode);
wprintf (L"getsockopt returns %d\n",
getsockopt (s, SOL_RFCOMM, SO_BTH_GET_MODE, (char *)&mode, &isize));
wprintf (L"mode = %d (%s)\n", mode, (mode == 0 ? L"active" : (mode == 1 ? L"hold" : (mode == 2 ? L"sniff" : (mode == 3 ? L"park" : L"???")))));
continue;
}
if (wcsicmp (szCommand, L"GETPOLICY") == 0) {
int policy = -1;
int isize = sizeof(policy);
wprintf (L"getsockopt returns %d\n",
getsockopt (s, SOL_RFCOMM, SO_BTH_GET_LINK_POLICY, (char *)&policy, &isize));
wprintf (L"policy = %d (%s %s %s %s)\n", policy, policy & 1 ? L"master-slave" : L"",
policy & 2 ? L"hold" : L"", policy & 4 ? L"sniff" : L"", policy & 8 ? L"park" : L"");
continue;
}
if (wcsnicmp (szCommand, L"SETPOLICY ", 10) == 0) {
WCHAR *szData = szCommand + 10;
unsigned short policy;
if (! GetUx (&szData, &policy, 4)) {
wprintf (L"Syntax: policy\n");
continue;
}
unsigned int ipolicy = policy;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SET_LINK_POLICY, (char *)&ipolicy, sizeof(ipolicy)));
continue;
}
if (wcsnicmp (szCommand, L"PARK ", 5) == 0) {
WCHAR *szData = szCommand + 5;
BTH_PARK_MODE pm;
if (! GetUx (&szData, &pm.beacon_max, 4)) {
wprintf (L"Syntax: beacon_max\n");
continue;
}
if (! GetUx (&szData, &pm.beacon_min, 4)) {
wprintf (L"Syntax: beacon_min\n");
continue;
}
pm.interval = 0;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_ENTER_PARK_MODE, (char *)&pm, sizeof(pm)));
wprintf (L"interval = %d\n", pm.interval);
continue;
}
if (wcsicmp (szCommand, L"UNPARK") == 0) {
int iIgnore = 0;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_EXIT_PARK_MODE, (char *)&iIgnore, sizeof(iIgnore)));
continue;
}
if (wcsnicmp (szCommand, L"HOLD ", 5) == 0) {
WCHAR *szData = szCommand + 5;
BTH_HOLD_MODE hm;
if (! GetUx (&szData, &hm.hold_mode_max, 4)) {
wprintf (L"Syntax: hold_mode_max\n");
continue;
}
if (! GetUx (&szData, &hm.hold_mode_min, 4)) {
wprintf (L"Syntax: hold_mode_min\n");
continue;
}
hm.interval = 0;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_ENTER_HOLD_MODE, (char *)&hm, sizeof(hm)));
wprintf (L"interval = %d\n", hm.interval);
continue;
}
if (wcsnicmp (szCommand, L"SNIFF ", 6) == 0) {
WCHAR *szData = szCommand + 6;
int c = 0;
BTH_SNIFF_MODE sm;
if (! GetUx (&szData, &sm.sniff_mode_max, 4)) {
wprintf (L"Syntax: sniff_mode_max\n");
continue;
}
if (! GetUx (&szData, &sm.sniff_mode_min, 4)) {
wprintf (L"Syntax: sniff_mode_min\n");
continue;
}
if (! GetUx (&szData, &sm.sniff_attempt, 4)) {
wprintf (L"Syntax: sniff_attempt\n");
continue;
}
if (! GetUx (&szData, &sm.sniff_timeout, 4)) {
wprintf (L"Syntax: sniff_timeout\n");
continue;
}
sm.interval = 0;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_ENTER_SNIFF_MODE, (char *)&sm, sizeof(sm)));
wprintf (L"interval = %d\n", sm.interval);
continue;
}
if (wcsicmp (szCommand, L"UNSNIFF") == 0) {
int iIgnore = 0;
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_EXIT_SNIFF_MODE, (char *)&iIgnore, sizeof(iIgnore)));
continue;
}
if (wcsnicmp (szCommand, L"PIN ", 4) == 0) {
WCHAR *szData = szCommand + 4;
int c = 0;
BTH_SOCKOPT_SECURITY bs;
unsigned char *b = (unsigned char *)bs.caData;
for ( ; ; ) {
if (! GetUx (&szData, b + c, 2))
break;
++c;
}
bs.iLength = c;
bs.btAddr = 0;
if (c > 0) {
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SET_PIN, (char *)&bs, sizeof(bs)));
} else
wprintf (L"Empty string!\n");
continue;
}
if (wcsnicmp (szCommand, L"MSC ", 4) == 0) {
WCHAR *p = szCommand + 4;
int x[2];
if (! GetUx (&p, &x[0], 8)) {
wprintf (L"v24 ???\n");
continue;
}
if (! GetUx (&p, &x[1], 8)) {
wprintf (L"br ???\n");
continue;
}
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SEND_MSC, (char *)x, sizeof(x)));
continue;
}
if (wcsnicmp (szCommand, L"RLS ", 4) == 0) {
WCHAR *p = szCommand + 4;
int x;
if (! GetUx (&p, &x, 8)) {
wprintf (L"rls ???\n");
continue;
}
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SEND_RLS, (char *)&x, sizeof(int)));
continue;
}
if (wcsnicmp (szCommand, L"XON ", 4) == 0) {
WCHAR *p = szCommand + 4;
unsigned int x;
if (! GetDI (&p, &x)) {
wprintf (L"rls ???\n");
continue;
}
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SET_XON_LIM, (char *)&x, sizeof(int)));
continue;
}
if (wcsnicmp (szCommand, L"XOFF ", 5) == 0) {
WCHAR *p = szCommand + 5;
unsigned int x;
if (! GetDI (&p, &x)) {
wprintf (L"rls ???\n");
continue;
}
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SET_XOFF_LIM, (char *)&x, sizeof(int)));
continue;
}
if (wcsnicmp (szCommand, L"SENDBUFF ", 9) == 0) {
WCHAR *p = szCommand + 9;
unsigned int x;
if (! GetDI (&p, &x)) {
wprintf (L"rls ???\n");
continue;
}
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SET_SEND_BUFFER, (char *)&x, sizeof(int)));
continue;
}
if (wcsnicmp (szCommand, L"RECVBUFF ", 9) == 0) {
WCHAR *p = szCommand + 9;
unsigned int x;
if (! GetDI (&p, &x)) {
wprintf (L"rls ???\n");
continue;
}
wprintf (L"setsockopt returns %d\n",
setsockopt (s, SOL_RFCOMM, SO_BTH_SET_RECV_BUFFER, (char *)&x, sizeof(int)));
continue;
}
if (wcsnicmp (szCommand, L"SEND ", 5) == 0) {
WCHAR *szName = szCommand + 5;
FILE *fp = _wfopen (szName, L"r");
if (fp) {
unsigned char b[BUF_MAX];
for ( ; ; ) {
int c = fread (b, 1, sizeof(b), fp);
if (c <= 0)
break;
int x = send (s, (char *)b, c, 0);
if (x != c) {
wprintf (L"send returns %d, Error = %d\n", x, WSAGetLastError ());
break;
}
}
fclose (fp);
} else
wprintf (L"Cannot open %s\n", szCommand);
continue;
}
if (wcsnicmp (szCommand, L"TEXT ", 5) == 0) {
WCHAR *szString = szCommand + 5;
int c = (wcslen (szString) + 1) * sizeof(WCHAR);
if (c > sizeof (WCHAR)) {
int x = send (s, (char *)szString, c, 0);
if (x != c)
wprintf (L"send returns %d, Error = %d\n", x, WSAGetLastError ());
} else
wprintf (L"Empty string!\n");
continue;
}
if (wcsnicmp (szCommand, L"BIN ", 4) == 0) {
WCHAR *szData = szCommand + 4;
int c = 0;
unsigned char *b = (unsigned char *)szCommand;
for ( ; ; ) {
if (! GetUx (&szData, b + c, 2))
break;
++c;
}
if (c > 0) {
int x = send (s, (char *)b, c, 0);
if (x != c)
wprintf (L"send returns %d, Error = %d\n", x, WSAGetLastError ());
} else
wprintf (L"Empty string!\n");
continue;
}
if (wcsicmp (szCommand, L"GETVERSION") == 0) {
BTH_REMOTE_VERSION bv;
int iRes;
int ilen = sizeof(bv);
iRes = getsockopt (s, SOL_RFCOMM, SO_BTH_GET_REMOTE_VER, (char *)&bv, &ilen);
if (iRes)
wprintf (L"SO_BTH_GET_LOCAL_VER : error %d\n", iRes);
else {
wprintf (L"lmp version %d\n", bv.lmp_version);
wprintf (L"lmp revision %d\n", bv.lmp_subversion);
wprintf (L"manufacturer: ");
switch (bv.manufacturer) {
case 0:
wprintf (L"Ericsson\n");
break;
case 1:
wprintf (L"Nokia\n");
break;
case 2:
wprintf (L"Intel\n");
break;
case 3:
wprintf (L"IBM\n");
break;
case 4:
wprintf (L"Toshiba\n");
break;
case 5:
wprintf (L"3COM\n");
break;
case 6:
wprintf (L"Microsoft\n");
break;
case 7:
wprintf (L"Lucent\n");
break;
case 8:
wprintf (L"Motorola\n");
break;
case 9:
wprintf (L"Infineon\n");
break;
case 10:
wprintf (L"CSR\n");
break;
case 11:
wprintf (L"Silicon Wave\n");
break;
case 12:
wprintf (L"Digianswer\n");
break;
default:
wprintf (L"Unknown, code %d\n", bv.manufacturer);
break;
}
DumpFeatures (bv.lmp_features);
}
continue;
}
wprintf (L"Command not understood...\n");
}
closesocket (s);
wprintf (L"Writer thread ended for socket 0x%08x\n", lpVoid);
return 0;
}
int ProcessSockOpts (SOCKET s, WCHAR **argv, int argc) {
while (argc > 0) {
unsigned int iOpt = 0;
int iName = 0;
WCHAR *sz = NULL;
if (wcsicmp (argv[0], L"AUTH") == 0)
iName = SO_BTH_AUTHENTICATE;
else if (wcsicmp (argv[0], L"ENCRYPT") == 0)
iName = SO_BTH_ENCRYPT;
else if ((wcsicmp (argv[0], L"MTU") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_MTU;
else if ((wcsicmp (argv[0], L"MTUMIN") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_MTU_MIN;
else if ((wcsicmp (argv[0], L"MTUMAX") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_MTU_MAX;
else if ((wcsicmp (argv[0], L"XON") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_XON_LIM;
else if ((wcsicmp (argv[0], L"XOFF") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_XOFF_LIM;
else if ((wcsicmp (argv[0], L"SENDBUFF") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_SEND_BUFFER;
else if ((wcsicmp (argv[0], L"RECVBUFF") == 0) && (argc > 1) && (sz = argv[1]) && (GetDI (&sz, &iOpt)))
iName = SO_BTH_SET_RECV_BUFFER;
else if ((wcsicmp (argv[0], L"PIN") == 0) && (argc > 1)) {
++argv;
--argc;
BTH_SOCKOPT_SECURITY bs;
bs.iLength = 0;
bs.btAddr = 0;
while ((bs.iLength < 16) && (argc > 0) && (sz = argv[0]) && GetUx (&sz, bs.caData + bs.iLength, 2)) {
++bs.iLength;
++argv;
--argc;
}
int iRes = setsockopt (s, SOL_RFCOMM, SO_BTH_SET_PIN, (char *)&bs, sizeof(bs));
if (iRes != ERROR_SUCCESS) {
wprintf (L"setsockopt returns %d for PIN\n", iRes);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -