author | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
commit | 50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (unidiff) | |
tree | 0d1939e2297fa7bbd8e1f2030f154463854164c6 /gammu/emb/common/device/bluetoth/bluez.c | |
parent | cf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff) | |
download | kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2 |
updated to latest gammu version
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.c | 29 |
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,25 +1,34 @@ | |||
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> |
14 | #include <sys/time.h> | 23 | #include <sys/time.h> |
15 | #include <unistd.h> | 24 | #include <unistd.h> |
16 | #include <bluetooth/bluetooth.h> | 25 | #include <bluetooth/bluetooth.h> |
17 | #include <bluetooth/rfcomm.h> | 26 | #include <bluetooth/rfcomm.h> |
18 | #include <bluetooth/sdp.h> | 27 | #include <bluetooth/sdp.h> |
19 | #include <bluetooth/sdp_lib.h> | 28 | #include <bluetooth/sdp_lib.h> |
20 | 29 | ||
21 | #include "../../gsmcomon.h" | 30 | #include "../../gsmcomon.h" |
22 | #include "../devfunc.h" | 31 | #include "../devfunc.h" |
23 | #include "bluetoth.h" | 32 | #include "bluetoth.h" |
24 | 33 | ||
25 | GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) | 34 | GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) |
@@ -60,148 +69,148 @@ GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) | |||
60 | 69 | ||
61 | d->hPhone = fd; | 70 | d->hPhone = fd; |
62 | return ERR_NONE; | 71 | return ERR_NONE; |
63 | } | 72 | } |
64 | 73 | ||
65 | #ifdef BLUETOOTH_RF_SEARCHING | 74 | #ifdef BLUETOOTH_RF_SEARCHING |
66 | 75 | ||
67 | struct search_context { | 76 | struct search_context { |
68 | char *svc; | 77 | char *svc; |
69 | uuid_t group; | 78 | uuid_t group; |
70 | int tree; | 79 | int tree; |
71 | uint32_t handle; | 80 | uint32_t handle; |
72 | }; | 81 | }; |
73 | 82 | ||
74 | static void print_service_desc(void *value, void *user) | 83 | static 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 | ||
96 | void print_access_protos(value, user) | 105 | void 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 | ||
104 | static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context) | 113 | static 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 | } |
126 | 135 | ||
127 | attrid = sdp_list_append(0, &range); | 136 | attrid = sdp_list_append(0, &range); |
128 | search = sdp_list_append(0, &context->group); | 137 | search = sdp_list_append(0, &context->group); |
129 | if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { | 138 | if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { |
130 | dbgprintf("Service Search failed: %s\n", strerror(errno)); | 139 | dbgprintf("Service Search failed: %s\n", strerror(errno)); |
131 | sdp_close(sess); | 140 | sdp_close(sess); |
132 | return ERR_UNKNOWN; | 141 | return ERR_UNKNOWN; |
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 | ||
174 | GSM_Error bluetooth_findchannel(GSM_StateMachine *s) | 183 | GSM_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); |
196 | if (error == ERR_NONE) return error; | 205 | if (error == ERR_NONE) return error; |
197 | } | 206 | } |
198 | return error; | 207 | return error; |
199 | } | 208 | } |
200 | 209 | ||
201 | #endif | 210 | #endif |
202 | #endif | 211 | #endif |
203 | #endif | 212 | #endif |
204 | 213 | ||
205 | /* How should editor hadle tabs in this file? Add editor commands here. | 214 | /* How should editor hadle tabs in this file? Add editor commands here. |
206 | * vim: noexpandtab sw=8 ts=8 sts=8: | 215 | * vim: noexpandtab sw=8 ts=8 sts=8: |
207 | */ | 216 | */ |