summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/device/bluetoth/bluez.c
Unidiff
Diffstat (limited to 'gammu/emb/common/device/bluetoth/bluez.c') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/device/bluetoth/bluez.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/gammu/emb/common/device/bluetoth/bluez.c b/gammu/emb/common/device/bluetoth/bluez.c
index 8a4807e..e7e8adf 100644
--- a/gammu/emb/common/device/bluetoth/bluez.c
+++ b/gammu/emb/common/device/bluetoth/bluez.c
@@ -1,13 +1,22 @@
1/* Based on work by Marcel Holtmann and other authors of Bluez */ 1/* Based on some work from Bluez (www.bluez.org)
2 * (C) 2000-2001 Qualcomm Incorporated
3 * (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
4 * (C) 2002-2004 Marcel Holtmann <marcel@holtmann.org>
5 * GNU GPL version 2
6 */
7/* based on some Marcel Holtmann work from Gnokii (www.gnokii.org)
8 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
9 * GNU GPL version 2 or later
10 */
2 11
3#include "../../gsmstate.h" 12#include "../../gsmstate.h"
4 13
5#ifdef GSM_ENABLE_BLUETOOTHDEVICE 14#ifdef GSM_ENABLE_BLUETOOTHDEVICE
6#ifdef GSM_ENABLE_BLUEZ 15#ifdef GSM_ENABLE_BLUEZ
7 16
8#include <stdlib.h> 17#include <stdlib.h>
9#include <stdio.h> 18#include <stdio.h>
10#include <fcntl.h> 19#include <fcntl.h>
11#include <errno.h> 20#include <errno.h>
12#include <string.h> 21#include <string.h>
13#include <sys/socket.h> 22#include <sys/socket.h>
@@ -72,54 +81,54 @@ struct search_context {
72}; 81};
73 82
74static void print_service_desc(void *value, void *user) 83static void print_service_desc(void *value, void *user)
75{ 84{
76 sdp_data_t *p = (sdp_data_t *)value; 85 sdp_data_t *p = (sdp_data_t *)value;
77 int i = 0, proto = 0, *channel = (int *)user; 86 int i = 0, proto = 0, *channel = (int *)user;
78 87
79 for (; p; p = p->next, i++) { 88 for (; p; p = p->next, i++) {
80 switch (p->dtd) { 89 switch (p->dtd) {
81 case SDP_UUID16: 90 case SDP_UUID16:
82 case SDP_UUID32: 91 case SDP_UUID32:
83 case SDP_UUID128: 92 case SDP_UUID128:
84 proto = 1;//sdp_uuid_to_proto(&p->val.uuid); 93 proto = sdp_uuid_to_proto(&p->val.uuid);
85 break; 94 break;
86 case SDP_UINT8: 95 case SDP_UINT8:
87 if (proto == RFCOMM_UUID) { 96 if (proto == RFCOMM_UUID) {
88 (*channel) = p->val.uint8; 97 (*channel) = p->val.uint8;
89 return; 98 return;
90 } 99 }
91 break; 100 break;
92 } 101 }
93 } 102 }
94} 103}
95 104
96void print_access_protos(value, user) 105void print_access_protos(value, user)
97{ 106{
98 sdp_list_t *protDescSeq = (sdp_list_t *)value; 107 sdp_list_t *protDescSeq = (sdp_list_t *)value;
99 int *channel = (int *)user; 108 int *channel = (int *)user;
100 109
101 sdp_list_foreach(protDescSeq,print_service_desc,channel); 110 sdp_list_foreach(protDescSeq,print_service_desc,channel);
102} 111}
103 112
104static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context) 113static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context)
105{ 114{
106 sdp_session_t *sess; 115 sdp_session_t *sess;
107 sdp_list_t *attrid, *search, *seq, *next, *proto = 0;
108 uint32_t range = 0x0000ffff;
109 char str[20];
110 sdp_record_t *rec; 116 sdp_record_t *rec;
117 sdp_list_t *attrid, *search, *seq, *next, *proto = 0;
111 sdp_data_t *d; 118 sdp_data_t *d;
112 bdaddr_t interface; 119 bdaddr_t interface;
120 uint32_t range = 0x0000ffff;
113 struct search_context subcontext; 121 struct search_context subcontext;
122 char str[20];
114 int channel,channel2; 123 int channel,channel2;
115 124
116 bacpy(&interface,BDADDR_ANY); 125 bacpy(&interface,BDADDR_ANY);
117 126
118 ba2str(bdaddr, str); 127 ba2str(bdaddr, str);
119 smprintf(s,"%s\n", str); 128 smprintf(s,"%s\n", str);
120 129
121 sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY); 130 sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY);
122 if (!sess) { 131 if (!sess) {
123 dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno)); 132 dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno));
124 return ERR_UNKNOWN; 133 return ERR_UNKNOWN;
125 } 134 }
@@ -133,63 +142,63 @@ static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, st
133 } 142 }
134 sdp_list_free(attrid, 0); 143 sdp_list_free(attrid, 0);
135 sdp_list_free(search, 0); 144 sdp_list_free(search, 0);
136 145
137 channel2 = -1; 146 channel2 = -1;
138 for (; seq; seq = next) { 147 for (; seq; seq = next) {
139 rec = (sdp_record_t *) seq->data; 148 rec = (sdp_record_t *) seq->data;
140 149
141 if (channel2 == -1) { 150 if (channel2 == -1) {
142 if (!context->tree) { 151 if (!context->tree) {
143 d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY); 152 d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY);
144 153
145 if (false) { 154 if (sdp_get_access_protos(rec,&proto) == 0) {
146 channel = -1; 155 channel = -1;
147 sdp_list_foreach(proto,print_access_protos,&channel); 156 sdp_list_foreach(proto,print_access_protos,&channel);
148 //sdp_list_free(proto,(sdp_free_func_t)sdp_data_free); 157 sdp_list_free(proto,(sdp_free_func_t)sdp_data_free);
149 } 158 }
150 smprintf(s,"Channel %i",channel); 159 smprintf(s,"Channel %i",channel);
151 if (d) smprintf(s," - \"%s\"",d->val.str); 160 if (d) smprintf(s," - \"%s\"",d->val.str);
152 smprintf(s,"\n"); 161 smprintf(s,"\n");
153 if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) { 162 if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) {
154 channel2 = channel; 163 channel2 = channel;
155 } 164 }
156 } 165 }
157 if (sdp_get_group_id(rec,&subcontext.group) != -1) { 166 if (sdp_get_group_id(rec,&subcontext.group) != -1) {
158 memcpy(&subcontext, context, sizeof(struct search_context)); 167 memcpy(&subcontext, context, sizeof(struct search_context));
159 if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext); 168 if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext);
160 } 169 }
161 } 170 }
162 171
163 next = seq->next; 172 next = seq->next;
164 free(seq); 173 free(seq);
165 //sdp_record_free(rec); 174 sdp_record_free(rec);
166 } 175 }
167 sdp_close(sess); 176 sdp_close(sess);
168 177
169 if (channel2 != -1) return bluetooth_connect(s, channel2, str); 178 if (channel2 != -1) return bluetooth_connect(s, channel2, str);
170 179
171 return ERR_UNKNOWN; 180 return ERR_NOTSUPPORTED;
172} 181}
173 182
174GSM_Error bluetooth_findchannel(GSM_StateMachine *s) 183GSM_Error bluetooth_findchannel(GSM_StateMachine *s)
175{ 184{
176 inquiry_info ii[20]; 185 inquiry_info ii[20];
177 uint8_t count = 0; 186 uint8_t count = 0;
178 int i; 187 int i;
179 struct search_context context; 188 struct search_context context;
180 GSM_Error error = ERR_NOTSUPPORTED; 189 GSM_Error error = ERR_NOTSUPPORTED;
181 190
182 memset(&context, '\0', sizeof(struct search_context)); 191 memset(&context, '\0', sizeof(struct search_context));
183 //sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP); 192 sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP);
184 193
185 if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) { 194 if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) {
186 dbgprintf("Searching for devices\n"); 195 dbgprintf("Searching for devices\n");
187 if (sdp_general_inquiry(ii, 20, 8, &count) < 0) { 196 if (sdp_general_inquiry(ii, 20, 8, &count) < 0) {
188 return ERR_UNKNOWN; 197 return ERR_UNKNOWN;
189 } 198 }
190 } else { 199 } else {
191 count = 1; 200 count = 1;
192 str2ba(s->CurrentConfig->Device,&ii[0].bdaddr); 201 str2ba(s->CurrentConfig->Device,&ii[0].bdaddr);
193 } 202 }
194 for (i=0;i<count;i++) { 203 for (i=0;i<count;i++) {
195 error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context); 204 error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context);