5 #include "../../gsmstate.h" 7 #ifdef GSM_ENABLE_BLUETOOTHDEVICE 15 #define WIN32_LEAN_AND_MEAN 21 #include "../../misc/coding/coding.h" 22 #include "../../gsmcomon.h" 23 #include "../devfunc.h" 35 smprintf(s,
"Connecting to RF channel %i\n",port);
41 WSAStartup(MAKEWORD(1,1), &wsaData);
47 if (d->
hPhone == INVALID_SOCKET) {
50 if (err == WSAEPROTOTYPE)
55 memset (&sab, 0,
sizeof(sab));
59 for (ch = device; *ch !=
'\0'; ch++){
60 if (*ch >=
'0' && *ch <=
'9') {
63 }
else if (*ch >=
'a' && *ch <=
'f') {
66 }
else if (*ch >=
'A' && *ch <=
'F') {
72 smprintf(s,
"Remote Bluetooth device is %02x:%02x:%02x:%02x:%02x:%02x\n",
80 if (connect (d->
hPhone, (
struct sockaddr *)&sab,
sizeof(sab)) != 0) {
89 smprintf(s,
"The I/O timed out at the Bluetooth radio level (PAGE_TIMEOUT).\n");
92 smprintf(s,
"The RFCOMM channel disconnected by remote peer.\n");
95 smprintf(s,
"The RFCOMM received DM response.\n");
98 smprintf(s,
"Unexpected network error.\n");
101 smprintf(s,
"The L2CAP channel disconnected by remote peer.\n");
104 smprintf(s,
"Error other than time-out at L2CAP or Bluetooth radio level.\n");
113 #ifdef BLUETOOTH_RF_SEARCHING 115 DEFINE_GUID(L2CAP_PROTOCOL_UUID, 0x00000100, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
118 #pragma comment(lib, "ws2_32.lib") 124 int score, bestscore = 0;
125 WSAQUERYSET querySet;
130 char addressAsString[1000];
131 DWORD bufferLength, addressSize;
132 WSAQUERYSET *pResults = (WSAQUERYSET*)&buffer;
135 memset(&querySet, 0,
sizeof(querySet));
136 querySet.dwSize =
sizeof(querySet);
137 protocol = L2CAP_PROTOCOL_UUID;
138 querySet.lpServiceClassId = &protocol;
139 querySet.dwNameSpace = NS_BTH;
140 querySet.lpszContext = address;
142 flags = LUP_FLUSHCACHE | LUP_RETURN_NAME |
143 LUP_RETURN_TYPE | LUP_RETURN_ADDR |
144 LUP_RETURN_BLOB | LUP_RETURN_COMMENT;
146 result = WSALookupServiceBegin(&querySet, flags, &handle);
149 bufferLength =
sizeof(buffer);
151 result = WSALookupServiceNext(handle, flags, &bufferLength, pResults);
152 if (result != 0)
break;
153 addressSize =
sizeof(addressAsString);
154 addressAsString[0] = 0;
155 if (WSAAddressToString(pResults->lpcsaBuffer->RemoteAddr.lpSockaddr,
156 pResults->lpcsaBuffer->RemoteAddr.iSockaddrLength, protocolInfo,
157 addressAsString,&addressSize)==0) {
158 smprintf(s,
"%s - ", addressAsString);
160 score = bluetooth_checkservicename(s, pResults->lpszServiceInstanceName);
161 smprintf(s,
"\"%s\" (score=%d)\n", pResults->lpszServiceInstanceName, score);
162 if (addressAsString[0] != 0) {
163 for (i=strlen(addressAsString)-1;i>0;i--) {
164 if (addressAsString[i] ==
':')
break;
166 if (score > bestscore) {
167 found = atoi(addressAsString+i+1);
172 result = WSALookupServiceEnd(handle);
183 int protocolInfoSize, result;
184 WSAPROTOCOL_INFO protocolInfo;
187 WSAQUERYSET querySet;
189 char addressAsString[1000];
190 DWORD bufferLength, addressSize;
191 WSAQUERYSET *pResults = (WSAQUERYSET*)&buffer;
205 if (d->
hPhone == INVALID_SOCKET) {
206 err = GetLastError();
208 if (err == WSAEPROTOTYPE)
210 smprintf(s,
"Failed to socket in bluetooth_open\n");
214 protocolInfoSize =
sizeof(protocolInfo);
215 if (getsockopt(d->
hPhone, SOL_SOCKET, SO_PROTOCOL_INFO,
216 (
char*)&protocolInfo, &protocolInfoSize) != 0)
220 smprintf(s,
"Failed to getsockopt in bluetooth_open\n");
226 bufferLength =
sizeof(buffer);
228 flags = LUP_RETURN_NAME | LUP_CONTAINERS |
229 LUP_RETURN_ADDR | LUP_FLUSHCACHE |
230 LUP_RETURN_TYPE | LUP_RETURN_BLOB | LUP_RES_SERVICE;
232 memset(&querySet, 0,
sizeof(querySet));
233 querySet.dwSize =
sizeof(querySet);
234 querySet.dwNameSpace = NS_BTH;
236 result = WSALookupServiceBegin(&querySet, flags, &handle);
239 smprintf(s,
"Failed to WSALookupServiceBegin in bluetooth_open\n");
244 result = WSALookupServiceNext(handle, flags, &bufferLength, pResults);
245 if (result != 0)
break;
247 smprintf(s,
"\"%s\"", pResults->lpszServiceInstanceName);
249 addressSize =
sizeof(addressAsString);
250 addressAsString[0] = 0;
251 if (WSAAddressToString(pResults->lpcsaBuffer->RemoteAddr.lpSockaddr,
252 pResults->lpcsaBuffer->RemoteAddr.iSockaddrLength, &protocolInfo,
253 addressAsString,&addressSize)==0) {
254 smprintf(s,
" - %s\n", addressAsString);
255 error = bluetooth_checkdevice(s, addressAsString,&protocolInfo);
262 result = WSALookupServiceEnd(handle);
268 result = WSALookupServiceEnd(handle);
GSM_Config * CurrentConfig
union GSM_Device::@0 Data
GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device)
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
GSM_Error bluetooth_findchannel(GSM_StateMachine *s)
#define GET_BYTE(num, byte)
int smprintf(GSM_StateMachine *s, const char *format,...)