diff options
Diffstat (limited to 'meta/packages')
25 files changed, 2313 insertions, 308 deletions
diff --git a/meta/packages/libgsmd/files/0001-Introduce-ports.patch b/meta/packages/libgsmd/files/0001-Introduce-ports.patch new file mode 100644 index 0000000000..b3ba3cb957 --- /dev/null +++ b/meta/packages/libgsmd/files/0001-Introduce-ports.patch | |||
@@ -0,0 +1,710 @@ | |||
1 | From 516d67c679101d1503dbd4c0613bcd6ff1b604e4 Mon Sep 17 00:00:00 2001 | ||
2 | From: Andrzej Zaborowski <balrog@zabor.org> | ||
3 | Date: Wed, 19 Sep 2007 14:03:28 +0200 | ||
4 | Subject: [PATCH] Introduce ports. | ||
5 | |||
6 | --- | ||
7 | include/gsmd/atcmd.h | 2 +- | ||
8 | include/gsmd/gsmd.h | 7 +- | ||
9 | include/gsmd/uart.h | 28 ++++++ | ||
10 | include/gsmd/vendorplugin.h | 4 +- | ||
11 | src/gsmd/Makefile.am | 2 +- | ||
12 | src/gsmd/atcmd.c | 177 +++++++++++++++++--------------------- | ||
13 | src/gsmd/gsmd.c | 64 ++------------ | ||
14 | src/gsmd/uart.c | 202 +++++++++++++++++++++++++++++++++++++++++++ | ||
15 | 8 files changed, 328 insertions(+), 158 deletions(-) | ||
16 | create mode 100644 include/gsmd/uart.h | ||
17 | create mode 100644 src/gsmd/uart.c | ||
18 | |||
19 | diff --git a/include/gsmd/atcmd.h b/include/gsmd/atcmd.h | ||
20 | index 0d6c62a..a1af6a0 100644 | ||
21 | --- a/include/gsmd/atcmd.h | ||
22 | +++ b/include/gsmd/atcmd.h | ||
23 | @@ -9,7 +9,7 @@ typedef int atcmd_cb_t(struct gsmd_atcmd *cmd, void *ctx, char *resp); | ||
24 | |||
25 | extern struct gsmd_atcmd *atcmd_fill(const char *cmd, int rlen, atcmd_cb_t *cb, void *ctx, u_int16_t id); | ||
26 | extern int atcmd_submit(struct gsmd *g, struct gsmd_atcmd *cmd); | ||
27 | -extern int atcmd_init(struct gsmd *g, int sockfd); | ||
28 | +extern int atcmd_init(struct gsmd *g, struct gsmd_port *port); | ||
29 | extern void atcmd_drain(int fd); | ||
30 | |||
31 | #endif /* __GSMD__ */ | ||
32 | diff --git a/include/gsmd/gsmd.h b/include/gsmd/gsmd.h | ||
33 | index ed334f1..4afdf66 100644 | ||
34 | --- a/include/gsmd/gsmd.h | ||
35 | +++ b/include/gsmd/gsmd.h | ||
36 | @@ -10,6 +10,7 @@ | ||
37 | #include <gsmd/machineplugin.h> | ||
38 | #include <gsmd/vendorplugin.h> | ||
39 | #include <gsmd/select.h> | ||
40 | +#include <gsmd/uart.h> | ||
41 | #include <gsmd/state.h> | ||
42 | |||
43 | void *gsmd_tallocs; | ||
44 | @@ -52,6 +53,7 @@ enum llparse_state { | ||
45 | #define MLPARSE_BUF_SIZE 65535 | ||
46 | |||
47 | struct llparser { | ||
48 | + struct gsmd_port *port; | ||
49 | enum llparse_state state; | ||
50 | unsigned int len; | ||
51 | unsigned int flags; | ||
52 | @@ -70,7 +72,7 @@ struct gsmd; | ||
53 | struct gsmd { | ||
54 | unsigned int flags; | ||
55 | int interpreter_ready; | ||
56 | - struct gsmd_fd gfd_uart; | ||
57 | + struct gsmd_uart uart; | ||
58 | struct gsmd_fd gfd_sock; | ||
59 | struct llparser llp; | ||
60 | struct llist_head users; | ||
61 | @@ -81,9 +83,10 @@ struct gsmd { | ||
62 | struct gsmd_device_state dev_state; | ||
63 | |||
64 | struct llist_head operators; /* cached list of operator names */ | ||
65 | - unsigned char *mlbuf; /* ml_parse buffer */ | ||
66 | + char *mlbuf; /* ml_parse buffer */ | ||
67 | unsigned int mlbuf_len; | ||
68 | int mlunsolicited; | ||
69 | + int clear_to_send; | ||
70 | }; | ||
71 | |||
72 | struct gsmd_user { | ||
73 | diff --git a/include/gsmd/uart.h b/include/gsmd/uart.h | ||
74 | new file mode 100644 | ||
75 | index 0000000..a006fa7 | ||
76 | --- /dev/null | ||
77 | +++ b/include/gsmd/uart.h | ||
78 | @@ -0,0 +1,28 @@ | ||
79 | +#ifndef __GSMD_UART_H | ||
80 | +#define __GSMD_UART_H | ||
81 | + | ||
82 | +#ifdef __GSMD__ | ||
83 | + | ||
84 | +struct gsmd_port { | ||
85 | + int (*write)(struct gsmd_port *port, const char data[], int len); | ||
86 | + int (*set_break)(struct gsmd_port *port, int state); | ||
87 | + /* more parameters here */ | ||
88 | + int (*newdata_cb)(void *opaque, const char data[], int len); | ||
89 | + void *newdata_opaque; | ||
90 | +}; | ||
91 | + | ||
92 | +struct gsmd_uart { | ||
93 | + struct gsmd_port port; | ||
94 | + struct gsmd_fd gfd; | ||
95 | + char txfifo[2048]; | ||
96 | + int tx_start; | ||
97 | + int tx_len; | ||
98 | +}; | ||
99 | + | ||
100 | +extern int set_baudrate(int fd, int baudrate, int hwflow); | ||
101 | +extern void uart_drain(int fd); | ||
102 | +extern int uart_init(struct gsmd_uart *uart, int sockfd); | ||
103 | + | ||
104 | +#endif /* __GSMD__ */ | ||
105 | + | ||
106 | +#endif | ||
107 | diff --git a/include/gsmd/vendorplugin.h b/include/gsmd/vendorplugin.h | ||
108 | index 1911fef..1c82790 100644 | ||
109 | --- a/include/gsmd/vendorplugin.h | ||
110 | +++ b/include/gsmd/vendorplugin.h | ||
111 | @@ -11,8 +11,8 @@ struct gsmd_unsolicit; | ||
112 | |||
113 | struct gsmd_vendor_plugin { | ||
114 | struct llist_head list; | ||
115 | - unsigned char *name; | ||
116 | - unsigned char *ext_chars; | ||
117 | + char *name; | ||
118 | + char *ext_chars; | ||
119 | unsigned int num_unsolicit; | ||
120 | const struct gsmd_unsolicit *unsolicit; | ||
121 | int (*detect)(struct gsmd *g); | ||
122 | diff --git a/src/gsmd/Makefile.am b/src/gsmd/Makefile.am | ||
123 | index 9ac45ee..110b757 100644 | ||
124 | --- a/src/gsmd/Makefile.am | ||
125 | +++ b/src/gsmd/Makefile.am | ||
126 | @@ -13,7 +13,7 @@ sbin_PROGRAMS = gsmd | ||
127 | gsmd_CFLAGS = -D PLUGINDIR=\"$(plugindir)\" | ||
128 | gsmd_SOURCES = gsmd.c atcmd.c select.c machine.c vendor.c unsolicited.c log.c \ | ||
129 | usock.c talloc.c timer.c operator_cache.c ext_response.c \ | ||
130 | - sms_cb.c sms_pdu.c | ||
131 | + sms_cb.c sms_pdu.c uart.c | ||
132 | gsmd_LDADD = -ldl | ||
133 | gsmd_LDFLAGS = -Wl,--export-dynamic | ||
134 | |||
135 | diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c | ||
136 | index 2ef6a10..27dfa41 100644 | ||
137 | --- a/src/gsmd/atcmd.c | ||
138 | +++ b/src/gsmd/atcmd.c | ||
139 | @@ -159,7 +159,8 @@ static int llparse_byte(struct llparser *llp, char byte) | ||
140 | return ret; | ||
141 | } | ||
142 | |||
143 | -static int llparse_string(struct llparser *llp, char *buf, unsigned int len) | ||
144 | +static int llparse_string(struct llparser *llp, const char *buf, | ||
145 | + unsigned int len) | ||
146 | { | ||
147 | while (len--) { | ||
148 | int rc = llparse_byte(llp, *(buf++)); | ||
149 | @@ -187,6 +188,55 @@ static int llparse_init(struct llparser *llp) | ||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | +/* See if we can now send more commands to the port */ | ||
154 | +static void atcmd_wake_queue(struct gsmd *g) | ||
155 | +{ | ||
156 | + int len, rc; | ||
157 | + char *cr; | ||
158 | + | ||
159 | + /* write pending commands to UART */ | ||
160 | + while (g->interpreter_ready && g->clear_to_send) { | ||
161 | + struct gsmd_atcmd *pos, *pos2; | ||
162 | + llist_for_each_entry_safe(pos, pos2, &g->pending_atcmds, list) { | ||
163 | + cr = strchr(pos->cur, '\n'); | ||
164 | + if (cr) | ||
165 | + len = cr - pos->cur; | ||
166 | + else | ||
167 | + len = pos->buflen; | ||
168 | + rc = g->llp.port->write(g->llp.port, pos->cur, len); | ||
169 | + if (rc == 0) { | ||
170 | + gsmd_log(GSMD_ERROR, | ||
171 | + "write returns 0, aborting\n"); | ||
172 | + break; | ||
173 | + } | ||
174 | + if (cr && rc == len) | ||
175 | + rc ++; /* Skip the \n */ | ||
176 | + pos->buflen -= rc; | ||
177 | + pos->cur += rc; | ||
178 | + g->llp.port->write(g->llp.port, "\r", 1); | ||
179 | + | ||
180 | + if (!pos->buflen) { | ||
181 | + /* success: remove from global list of | ||
182 | + * to-be-sent atcmds */ | ||
183 | + llist_del(&pos->list); | ||
184 | + /* append to global list of executing atcmds */ | ||
185 | + llist_add_tail(&pos->list, &g->busy_atcmds); | ||
186 | + | ||
187 | + /* we only send one cmd at the moment */ | ||
188 | + g->clear_to_send = 0; | ||
189 | + break; | ||
190 | + } else { | ||
191 | + /* The write was short or the atcmd has more | ||
192 | + * lines to send after a "> ". */ | ||
193 | + if (rc < len) | ||
194 | + break; | ||
195 | + g->clear_to_send = 0; | ||
196 | + break; | ||
197 | + } | ||
198 | + } | ||
199 | + } | ||
200 | +} | ||
201 | + | ||
202 | /* mid-level parser */ | ||
203 | |||
204 | static int parse_final_result(const char *res) | ||
205 | @@ -216,6 +266,7 @@ static int ml_parse(const char *buf, int len, void *ctx) | ||
206 | g->interpreter_ready = 1; | ||
207 | gsmd_initsettings(g); | ||
208 | gmsd_alive_start(g); | ||
209 | + atcmd_wake_queue(g); | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | @@ -316,6 +367,7 @@ static int ml_parse(const char *buf, int len, void *ctx) | ||
214 | } else { | ||
215 | DEBUGP("Calling cmd->cb()\n"); | ||
216 | cmd->resp = g->mlbuf; | ||
217 | + g->mlbuf[g->mlbuf_len] = 0; | ||
218 | rc = cmd->cb(cmd, cmd->ctx, cmd->resp); | ||
219 | DEBUGP("Clearing mlbuf\n"); | ||
220 | } | ||
221 | @@ -370,12 +422,15 @@ static int ml_parse(const char *buf, int len, void *ctx) | ||
222 | if (g->mlbuf_len) | ||
223 | g->mlbuf[g->mlbuf_len ++] = '\n'; | ||
224 | DEBUGP("Appending buf to mlbuf\n"); | ||
225 | - if (len > MLPARSE_BUF_SIZE - g->mlbuf_len) | ||
226 | + if (len > MLPARSE_BUF_SIZE - g->mlbuf_len) { | ||
227 | len = MLPARSE_BUF_SIZE - g->mlbuf_len; | ||
228 | + gsmd_log(GSMD_NOTICE, "g->mlbuf overrun\n"); | ||
229 | + } | ||
230 | memcpy(g->mlbuf + g->mlbuf_len, buf, len); | ||
231 | g->mlbuf_len += len; | ||
232 | |||
233 | if (g->mlunsolicited) { | ||
234 | + g->mlbuf[g->mlbuf_len] = 0; | ||
235 | rc = unsolicited_parse(g, g->mlbuf, g->mlbuf_len, | ||
236 | strchr(g->mlbuf, ':') + 1); | ||
237 | if (rc == -EAGAIN) { | ||
238 | @@ -422,8 +477,11 @@ final_cb: | ||
239 | |||
240 | /* if we're finished with current commands, but still have pending | ||
241 | * commands: we want to WRITE again */ | ||
242 | - if (llist_empty(&g->busy_atcmds) && !llist_empty(&g->pending_atcmds)) | ||
243 | - g->gfd_uart.when |= GSMD_FD_WRITE; | ||
244 | + if (llist_empty(&g->busy_atcmds)) { | ||
245 | + g->clear_to_send = 1; | ||
246 | + if (!llist_empty(&g->pending_atcmds)) | ||
247 | + atcmd_wake_queue(g); | ||
248 | + } | ||
249 | |||
250 | return rc; | ||
251 | } | ||
252 | @@ -433,85 +491,23 @@ static int atcmd_prompt(void *data) | ||
253 | { | ||
254 | struct gsmd *g = data; | ||
255 | |||
256 | - g->gfd_uart.when |= GSMD_FD_WRITE; | ||
257 | + g->clear_to_send = 1; | ||
258 | + atcmd_wake_queue(g); | ||
259 | } | ||
260 | |||
261 | /* callback to be called if [virtual] UART has some data for us */ | ||
262 | -static int atcmd_select_cb(int fd, unsigned int what, void *data) | ||
263 | +static int atcmd_newdata_cb(void *opaque, const char data[], int len) | ||
264 | { | ||
265 | - int len, rc; | ||
266 | - static char rxbuf[1024]; | ||
267 | - struct gsmd *g = data; | ||
268 | - char *cr; | ||
269 | - | ||
270 | - if (what & GSMD_FD_READ) { | ||
271 | - memset(rxbuf, 0, sizeof(rxbuf)); | ||
272 | - while ((len = read(fd, rxbuf, sizeof(rxbuf)))) { | ||
273 | - if (len < 0) { | ||
274 | - if (errno == EAGAIN) | ||
275 | - return 0; | ||
276 | - gsmd_log(GSMD_NOTICE, "ERROR reading from fd %u: %d (%s)\n", fd, len, | ||
277 | - strerror(errno)); | ||
278 | - return len; | ||
279 | - } | ||
280 | - rc = llparse_string(&g->llp, rxbuf, len); | ||
281 | - if (rc < 0) { | ||
282 | - gsmd_log(GSMD_ERROR, "ERROR during llparse_string: %d\n", rc); | ||
283 | - return rc; | ||
284 | - } | ||
285 | - } | ||
286 | - } | ||
287 | - | ||
288 | - /* write pending commands to UART */ | ||
289 | - if ((what & GSMD_FD_WRITE) && g->interpreter_ready) { | ||
290 | - struct gsmd_atcmd *pos, *pos2; | ||
291 | - llist_for_each_entry_safe(pos, pos2, &g->pending_atcmds, list) { | ||
292 | - cr = strchr(pos->cur, '\n'); | ||
293 | - if (cr) | ||
294 | - len = cr - pos->cur; | ||
295 | - else | ||
296 | - len = pos->buflen - 1; /* assuming zero-terminated strings */ | ||
297 | - rc = write(fd, pos->cur, len); | ||
298 | - if (rc == 0) { | ||
299 | - gsmd_log(GSMD_ERROR, "write returns 0, aborting\n"); | ||
300 | - break; | ||
301 | - } else if (rc < 0) { | ||
302 | - gsmd_log(GSMD_ERROR, "error during write to fd %d: %d\n", | ||
303 | - fd, rc); | ||
304 | - return rc; | ||
305 | - } | ||
306 | - if (!cr || rc == len) | ||
307 | - rc ++; /* Skip the \n or \0 */ | ||
308 | - pos->buflen -= rc; | ||
309 | - pos->cur += rc; | ||
310 | - write(fd, "\r", 1); | ||
311 | - | ||
312 | - if (!pos->buflen) { | ||
313 | - /* success: remove from global list of | ||
314 | - * to-be-sent atcmds */ | ||
315 | - llist_del(&pos->list); | ||
316 | - /* append to global list of executing atcmds */ | ||
317 | - llist_add_tail(&pos->list, &g->busy_atcmds); | ||
318 | - | ||
319 | - /* we only send one cmd at the moment */ | ||
320 | - break; | ||
321 | - } else { | ||
322 | - /* The write was short or the atcmd has more | ||
323 | - * lines to send after a "> ". */ | ||
324 | - if (rc < len) | ||
325 | - return 0; | ||
326 | - break; | ||
327 | - } | ||
328 | - } | ||
329 | + struct gsmd *g = opaque; | ||
330 | + int rc; | ||
331 | |||
332 | - /* Either pending_atcmds is empty or a command has to wait */ | ||
333 | - g->gfd_uart.when &= ~GSMD_FD_WRITE; | ||
334 | - } | ||
335 | + rc = llparse_string(&g->llp, data, len); | ||
336 | + if (rc < 0) | ||
337 | + gsmd_log(GSMD_ERROR, "ERROR during llparse_string: %d\n", rc); | ||
338 | |||
339 | - return 0; | ||
340 | + return rc; | ||
341 | } | ||
342 | |||
343 | - | ||
344 | struct gsmd_atcmd *atcmd_fill(const char *cmd, int rlen, | ||
345 | atcmd_cb_t cb, void *ctx, u_int16_t id) | ||
346 | { | ||
347 | @@ -544,36 +540,18 @@ int atcmd_submit(struct gsmd *g, struct gsmd_atcmd *cmd) | ||
348 | { | ||
349 | DEBUGP("submitting command `%s'\n", cmd->buf); | ||
350 | |||
351 | - if (llist_empty(&g->pending_atcmds)) | ||
352 | - g->gfd_uart.when |= GSMD_FD_WRITE; | ||
353 | + llist_empty(&g->pending_atcmds); | ||
354 | llist_add_tail(&cmd->list, &g->pending_atcmds); | ||
355 | + atcmd_wake_queue(g); | ||
356 | |||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | -void atcmd_drain(int fd) | ||
361 | -{ | ||
362 | - int rc; | ||
363 | - struct termios t; | ||
364 | - rc = tcflush(fd, TCIOFLUSH); | ||
365 | - rc = tcgetattr(fd, &t); | ||
366 | - DEBUGP("c_iflag = 0x%08x, c_oflag = 0x%08x, c_cflag = 0x%08x, c_lflag = 0x%08x\n", | ||
367 | - t.c_iflag, t.c_oflag, t.c_cflag, t.c_lflag); | ||
368 | - t.c_iflag = t.c_oflag = 0; | ||
369 | - cfmakeraw(&t); | ||
370 | - rc = tcsetattr(fd, TCSANOW, &t); | ||
371 | -} | ||
372 | - | ||
373 | /* init atcmd parser */ | ||
374 | -int atcmd_init(struct gsmd *g, int sockfd) | ||
375 | +int atcmd_init(struct gsmd *g, struct gsmd_port *port) | ||
376 | { | ||
377 | __atcmd_ctx = talloc_named_const(gsmd_tallocs, 1, "atcmds"); | ||
378 | |||
379 | - g->gfd_uart.fd = sockfd; | ||
380 | - g->gfd_uart.when = GSMD_FD_READ; | ||
381 | - g->gfd_uart.data = g; | ||
382 | - g->gfd_uart.cb = &atcmd_select_cb; | ||
383 | - | ||
384 | INIT_LLIST_HEAD(&g->pending_atcmds); | ||
385 | INIT_LLIST_HEAD(&g->busy_atcmds); | ||
386 | |||
387 | @@ -581,7 +559,9 @@ int atcmd_init(struct gsmd *g, int sockfd) | ||
388 | |||
389 | g->mlbuf_len = 0; | ||
390 | g->mlunsolicited = 0; | ||
391 | + g->clear_to_send = 1; | ||
392 | |||
393 | + g->llp.port = port; | ||
394 | g->llp.cur = g->llp.buf; | ||
395 | g->llp.len = sizeof(g->llp.buf); | ||
396 | g->llp.cb = &ml_parse; | ||
397 | @@ -589,5 +569,8 @@ int atcmd_init(struct gsmd *g, int sockfd) | ||
398 | g->llp.ctx = g; | ||
399 | g->llp.flags = LGSM_ATCMD_F_EXTENDED; | ||
400 | |||
401 | - return gsmd_register_fd(&g->gfd_uart); | ||
402 | + port->newdata_opaque = g; | ||
403 | + port->newdata_cb = atcmd_newdata_cb; | ||
404 | + | ||
405 | + return 0; | ||
406 | } | ||
407 | diff --git a/src/gsmd/gsmd.c b/src/gsmd/gsmd.c | ||
408 | index 51b4f2c..846bd17 100644 | ||
409 | --- a/src/gsmd/gsmd.c | ||
410 | +++ b/src/gsmd/gsmd.c | ||
411 | @@ -26,7 +26,6 @@ | ||
412 | #include <string.h> | ||
413 | #include <errno.h> | ||
414 | #include <fcntl.h> | ||
415 | -#include <termios.h> | ||
416 | #include <signal.h> | ||
417 | |||
418 | #define _GNU_SOURCE | ||
419 | @@ -247,56 +246,6 @@ int gsmd_initsettings(struct gsmd *gsmd) | ||
420 | return atcmd_submit(gsmd, cmd); | ||
421 | } | ||
422 | |||
423 | -struct bdrt { | ||
424 | - int bps; | ||
425 | - u_int32_t b; | ||
426 | -}; | ||
427 | - | ||
428 | -static struct bdrt bdrts[] = { | ||
429 | - { 0, B0 }, | ||
430 | - { 9600, B9600 }, | ||
431 | - { 19200, B19200 }, | ||
432 | - { 38400, B38400 }, | ||
433 | - { 57600, B57600 }, | ||
434 | - { 115200, B115200 }, | ||
435 | - { 230400, B230400 }, | ||
436 | - { 460800, B460800 }, | ||
437 | - { 921600, B921600 }, | ||
438 | -}; | ||
439 | - | ||
440 | -static int set_baudrate(int fd, int baudrate, int hwflow) | ||
441 | -{ | ||
442 | - int i; | ||
443 | - u_int32_t bd = 0; | ||
444 | - struct termios ti; | ||
445 | - | ||
446 | - for (i = 0; i < ARRAY_SIZE(bdrts); i++) { | ||
447 | - if (bdrts[i].bps == baudrate) | ||
448 | - bd = bdrts[i].b; | ||
449 | - } | ||
450 | - if (bd == 0) | ||
451 | - return -EINVAL; | ||
452 | - | ||
453 | - i = tcgetattr(fd, &ti); | ||
454 | - if (i < 0) | ||
455 | - return i; | ||
456 | - | ||
457 | - i = cfsetispeed(&ti, B0); | ||
458 | - if (i < 0) | ||
459 | - return i; | ||
460 | - | ||
461 | - i = cfsetospeed(&ti, bd); | ||
462 | - if (i < 0) | ||
463 | - return i; | ||
464 | - | ||
465 | - if (hwflow) | ||
466 | - ti.c_cflag |= CRTSCTS; | ||
467 | - else | ||
468 | - ti.c_cflag &= ~CRTSCTS; | ||
469 | - | ||
470 | - return tcsetattr(fd, 0, &ti); | ||
471 | -} | ||
472 | - | ||
473 | static int gsmd_initialize(struct gsmd *g) | ||
474 | { | ||
475 | INIT_LLIST_HEAD(&g->users); | ||
476 | @@ -478,14 +427,19 @@ int main(int argc, char **argv) | ||
477 | if (wait >= 0) | ||
478 | g.interpreter_ready = !wait; | ||
479 | |||
480 | - if (atcmd_init(&g, fd) < 0) { | ||
481 | + if (uart_init(&g.uart, fd) < 0) { | ||
482 | fprintf(stderr, "can't initialize UART device\n"); | ||
483 | exit(1); | ||
484 | } | ||
485 | |||
486 | - write(fd, "\r", 1); | ||
487 | - sleep(1); | ||
488 | - atcmd_drain(fd); | ||
489 | + if (atcmd_init(&g, &g.uart.port) < 0) { | ||
490 | + fprintf(stderr, "can't initialize AT parser\n"); | ||
491 | + exit(1); | ||
492 | + } | ||
493 | + write(fd, "\r", 1); | ||
494 | + sleep(1); | ||
495 | + | ||
496 | + uart_drain(fd); | ||
497 | |||
498 | if (usock_init(&g) < 0) { | ||
499 | fprintf(stderr, "can't open unix socket\n"); | ||
500 | diff --git a/src/gsmd/uart.c b/src/gsmd/uart.c | ||
501 | new file mode 100644 | ||
502 | index 0000000..22a4a5c | ||
503 | --- /dev/null | ||
504 | +++ b/src/gsmd/uart.c | ||
505 | @@ -0,0 +1,202 @@ | ||
506 | +/* Wrapper for the physical UART in a struct gsmd_port abstraction. | ||
507 | + * | ||
508 | + * Copyright (C) 2007 OpenMoko, Inc. | ||
509 | + * Written by Andrzej Zaborowski <andrew@openedhand.com> | ||
510 | + * | ||
511 | + * This program is free software; you can redistribute it and/or | ||
512 | + * modify it under the terms of the GNU General Public License as | ||
513 | + * published by the Free Software Foundation; either version 2 of | ||
514 | + * the License, or (at your option) any later version. | ||
515 | + * | ||
516 | + * This program is distributed in the hope that it will be useful, | ||
517 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
518 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
519 | + * GNU General Public License for more details. | ||
520 | + * | ||
521 | + * You should have received a copy of the GNU General Public License | ||
522 | + * along with this program; if not, write to the Free Software | ||
523 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
524 | + * MA 02111-1307 USA | ||
525 | + */ | ||
526 | + | ||
527 | +#include <string.h> | ||
528 | +#include <fcntl.h> | ||
529 | +#include <termios.h> | ||
530 | +#include <unistd.h> | ||
531 | +#include <errno.h> | ||
532 | + | ||
533 | +#include "gsmd.h" | ||
534 | + | ||
535 | +#include <gsmd/gsmd.h> | ||
536 | + | ||
537 | +void uart_drain(int fd) | ||
538 | +{ | ||
539 | + int rc; | ||
540 | + struct termios t; | ||
541 | + rc = tcflush(fd, TCIOFLUSH); | ||
542 | + rc = tcgetattr(fd, &t); | ||
543 | + DEBUGP( | ||
544 | + "c_iflag = 0x%08x, c_oflag = 0x%08x, " | ||
545 | + "c_cflag = 0x%08x, c_lflag = 0x%08x\n", | ||
546 | + t.c_iflag, t.c_oflag, t.c_cflag, t.c_lflag); | ||
547 | + t.c_iflag = t.c_oflag = 0; | ||
548 | + cfmakeraw(&t); | ||
549 | + rc = tcsetattr(fd, TCSANOW, &t); | ||
550 | +} | ||
551 | + | ||
552 | +struct bdrt { | ||
553 | + int bps; | ||
554 | + u_int32_t b; | ||
555 | +}; | ||
556 | + | ||
557 | +static struct bdrt bdrts[] = { | ||
558 | + { 0, B0 }, | ||
559 | + { 9600, B9600 }, | ||
560 | + { 19200, B19200 }, | ||
561 | + { 38400, B38400 }, | ||
562 | + { 57600, B57600 }, | ||
563 | + { 115200, B115200 }, | ||
564 | + { 230400, B230400 }, | ||
565 | + { 460800, B460800 }, | ||
566 | + { 921600, B921600 }, | ||
567 | +}; | ||
568 | + | ||
569 | +int set_baudrate(int fd, int baudrate, int hwflow) | ||
570 | +{ | ||
571 | + int i; | ||
572 | + u_int32_t bd = 0; | ||
573 | + struct termios ti; | ||
574 | + | ||
575 | + for (i = 0; i < ARRAY_SIZE(bdrts); i++) { | ||
576 | + if (bdrts[i].bps == baudrate) | ||
577 | + bd = bdrts[i].b; | ||
578 | + } | ||
579 | + if (bd == 0) | ||
580 | + return -EINVAL; | ||
581 | + | ||
582 | + i = tcgetattr(fd, &ti); | ||
583 | + if (i < 0) | ||
584 | + return i; | ||
585 | + | ||
586 | + i = cfsetispeed(&ti, B0); | ||
587 | + if (i < 0) | ||
588 | + return i; | ||
589 | + | ||
590 | + i = cfsetospeed(&ti, bd); | ||
591 | + if (i < 0) | ||
592 | + return i; | ||
593 | + | ||
594 | + if (hwflow) | ||
595 | + ti.c_cflag |= CRTSCTS; | ||
596 | + else | ||
597 | + ti.c_cflag &= ~CRTSCTS; | ||
598 | + | ||
599 | + return tcsetattr(fd, 0, &ti); | ||
600 | +} | ||
601 | + | ||
602 | +static int uart_select_cb(int fd, unsigned int what, void *data) | ||
603 | +{ | ||
604 | + struct gsmd_uart *uart = (struct gsmd_uart *) data; | ||
605 | + static char rxbuf[2048]; | ||
606 | + int rc, len; | ||
607 | + | ||
608 | + if ((what & GSMD_FD_READ) && uart->port.newdata_cb) { | ||
609 | + while ((len = read(fd, rxbuf, sizeof(rxbuf)))) { | ||
610 | + if (len < 0) { | ||
611 | + if (errno == EAGAIN || errno == EINTR) | ||
612 | + return 0; | ||
613 | + gsmd_log(GSMD_NOTICE, "ERROR reading from " | ||
614 | + "fd %u: %d (%s)\n", fd, errno, | ||
615 | + strerror(errno)); | ||
616 | + return -errno; | ||
617 | + } | ||
618 | + | ||
619 | + rc = uart->port.newdata_cb( | ||
620 | + uart->port.newdata_opaque, | ||
621 | + rxbuf, | ||
622 | + len); | ||
623 | + if (rc < 0) | ||
624 | + return rc; | ||
625 | + } | ||
626 | + } | ||
627 | + | ||
628 | + /* Write pending data to UART. */ | ||
629 | + if ((what & GSMD_FD_WRITE) && uart->tx_len) { | ||
630 | + while (uart->tx_start + uart->tx_len >= sizeof(uart->txfifo)) { | ||
631 | + len = sizeof(uart->txfifo) - uart->tx_start; | ||
632 | + rc = write(fd, &uart->txfifo[uart->tx_start], len); | ||
633 | + if (rc < 0 && errno != EINTR) { | ||
634 | + if (errno == EAGAIN) | ||
635 | + return 0; | ||
636 | + gsmd_log(GSMD_NOTICE, "ERROR writing " | ||
637 | + "fd %u: %d (%s)\n", fd, errno, | ||
638 | + strerror(errno)); | ||
639 | + return -errno; | ||
640 | + } | ||
641 | + | ||
642 | + if (rc > 0) { | ||
643 | + uart->tx_start += rc; | ||
644 | + uart->tx_len -= rc; | ||
645 | + } | ||
646 | + } | ||
647 | + uart->tx_start &= sizeof(uart->txfifo) - 1; | ||
648 | + | ||
649 | + while (uart->tx_len) { | ||
650 | + rc = write(fd, &uart->txfifo[uart->tx_start], | ||
651 | + uart->tx_len); | ||
652 | + if (rc < 0 && errno != EINTR) { | ||
653 | + if (errno == EAGAIN) | ||
654 | + return 0; | ||
655 | + gsmd_log(GSMD_NOTICE, "ERROR writing " | ||
656 | + "fd %u: %d (%s)\n", fd, errno, | ||
657 | + strerror(errno)); | ||
658 | + return -errno; | ||
659 | + } | ||
660 | + | ||
661 | + if (rc > 0) { | ||
662 | + uart->tx_start += rc; | ||
663 | + uart->tx_len -= rc; | ||
664 | + } | ||
665 | + } | ||
666 | + | ||
667 | + /* If we reached here, there's no more data for the moment. */ | ||
668 | + uart->gfd.when &= ~GSMD_FD_WRITE; | ||
669 | + } | ||
670 | + | ||
671 | + return 0; | ||
672 | +} | ||
673 | + | ||
674 | +static int uart_write(struct gsmd_port *port, const char data[], int len) | ||
675 | +{ | ||
676 | + struct gsmd_uart *uart = (struct gsmd_uart *) port; | ||
677 | + int start = (uart->tx_start + uart->tx_len) & | ||
678 | + (sizeof(uart->txfifo) - 1); | ||
679 | + int space = sizeof(uart->txfifo) - start; | ||
680 | + | ||
681 | + if (uart->tx_len + len > sizeof(uart->txfifo)) | ||
682 | + len = sizeof(uart->txfifo) - uart->tx_len; | ||
683 | + | ||
684 | + if (len) | ||
685 | + uart->gfd.when |= GSMD_FD_WRITE; | ||
686 | + | ||
687 | + if (len > space) { | ||
688 | + memcpy(uart->txfifo + start, data, space); | ||
689 | + memcpy(uart->txfifo, data + space, len - space); | ||
690 | + } else | ||
691 | + memcpy(uart->txfifo + start, data, len); | ||
692 | + | ||
693 | + uart->tx_len += len; | ||
694 | + return len; | ||
695 | +} | ||
696 | + | ||
697 | +int uart_init(struct gsmd_uart *uart, int sockfd) | ||
698 | +{ | ||
699 | + uart->gfd.fd = sockfd; | ||
700 | + uart->gfd.when = GSMD_FD_READ; | ||
701 | + uart->gfd.data = uart; | ||
702 | + uart->gfd.cb = &uart_select_cb; | ||
703 | + | ||
704 | + uart->port.write = uart_write; | ||
705 | + | ||
706 | + return gsmd_register_fd(&uart->gfd); | ||
707 | +} | ||
708 | -- | ||
709 | 1.5.2.1 | ||
710 | |||
diff --git a/meta/packages/libgsmd/files/0002-Flush-all-pending-commands-before-restarting-the-mod.patch b/meta/packages/libgsmd/files/0002-Flush-all-pending-commands-before-restarting-the-mod.patch new file mode 100644 index 0000000000..3683596389 --- /dev/null +++ b/meta/packages/libgsmd/files/0002-Flush-all-pending-commands-before-restarting-the-mod.patch | |||
@@ -0,0 +1,74 @@ | |||
1 | From 1078f7aced63c6216bffe649930b97c9ccf9a16e Mon Sep 17 00:00:00 2001 | ||
2 | From: Andrzej Zaborowski <balrog@zabor.org> | ||
3 | Date: Wed, 19 Sep 2007 14:04:50 +0200 | ||
4 | Subject: [PATCH] Flush all pending commands before restarting the modem initialisation. | ||
5 | |||
6 | --- | ||
7 | include/gsmd/gsmd.h | 1 + | ||
8 | src/gsmd/atcmd.c | 21 +++++++++++++++++++++ | ||
9 | src/gsmd/timer.c | 8 ++++++++ | ||
10 | 3 files changed, 30 insertions(+), 0 deletions(-) | ||
11 | |||
12 | diff --git a/include/gsmd/gsmd.h b/include/gsmd/gsmd.h | ||
13 | index 4afdf66..6ac9d8e 100644 | ||
14 | --- a/include/gsmd/gsmd.h | ||
15 | +++ b/include/gsmd/gsmd.h | ||
16 | @@ -131,6 +131,7 @@ struct gsmd_timer { | ||
17 | |||
18 | int gsmd_timer_init(void); | ||
19 | void gmsd_timer_check_n_run(void); | ||
20 | +void gsmd_timer_reset(void); | ||
21 | |||
22 | struct gsmd_timer *gsmd_timer_alloc(void); | ||
23 | int gsmd_timer_register(struct gsmd_timer *timer); | ||
24 | diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c | ||
25 | index 27dfa41..2f6cee2 100644 | ||
26 | --- a/src/gsmd/atcmd.c | ||
27 | +++ b/src/gsmd/atcmd.c | ||
28 | @@ -264,6 +264,27 @@ static int ml_parse(const char *buf, int len, void *ctx) | ||
29 | if (strlen(buf) == 0 || | ||
30 | !strcmp(buf, "AT-Command Interpreter ready")) { | ||
31 | g->interpreter_ready = 1; | ||
32 | + g->clear_to_send = 1; | ||
33 | + | ||
34 | + /* Flush current queue and reinitialise */ | ||
35 | + while (!llist_empty(&g->busy_atcmds)) { | ||
36 | + cmd = llist_entry(g->busy_atcmds.next, | ||
37 | + struct gsmd_atcmd, list); | ||
38 | + gsmd_log(GSMD_NOTICE, "discarding busy cmd %s\n", | ||
39 | + cmd->buf); | ||
40 | + llist_del(&cmd->list); | ||
41 | + talloc_free(cmd); | ||
42 | + } | ||
43 | + while (!llist_empty(&g->pending_atcmds)) { | ||
44 | + cmd = llist_entry(g->pending_atcmds.next, | ||
45 | + struct gsmd_atcmd, list); | ||
46 | + gsmd_log(GSMD_NOTICE, "discarding pending cmd %s\n", | ||
47 | + cmd->buf); | ||
48 | + llist_del(&cmd->list); | ||
49 | + talloc_free(cmd); | ||
50 | + } | ||
51 | + | ||
52 | + gsmd_timer_reset(); | ||
53 | gsmd_initsettings(g); | ||
54 | gmsd_alive_start(g); | ||
55 | atcmd_wake_queue(g); | ||
56 | diff --git a/src/gsmd/timer.c b/src/gsmd/timer.c | ||
57 | index 5200690..8877275 100644 | ||
58 | --- a/src/gsmd/timer.c | ||
59 | +++ b/src/gsmd/timer.c | ||
60 | @@ -215,3 +215,11 @@ void gsmd_timer_unregister(struct gsmd_timer *timer) | ||
61 | /* re-calculate next expiration */ | ||
62 | calc_next_expiration(); | ||
63 | } | ||
64 | + | ||
65 | +void gsmd_timer_reset(void) | ||
66 | +{ | ||
67 | + while (!llist_empty(&gsmd_timers)) | ||
68 | + /* TODO: free associated resources (e.g timer->cancel_cb()) */ | ||
69 | + llist_del(&llist_entry(gsmd_timers.next, | ||
70 | + struct gsmd_timer, list)->list); | ||
71 | +} | ||
72 | -- | ||
73 | 1.5.2.1 | ||
74 | |||
diff --git a/meta/packages/libgsmd/files/0003-Correctly-segment-incoming-usock-data-into-packets.patch b/meta/packages/libgsmd/files/0003-Correctly-segment-incoming-usock-data-into-packets.patch new file mode 100644 index 0000000000..984acc9369 --- /dev/null +++ b/meta/packages/libgsmd/files/0003-Correctly-segment-incoming-usock-data-into-packets.patch | |||
@@ -0,0 +1,77 @@ | |||
1 | From 8af1bb4a0d0df9baa80859c5f7f56cbd7634aded Mon Sep 17 00:00:00 2001 | ||
2 | From: Andrzej Zaborowski <balrog@zabor.org> | ||
3 | Date: Wed, 19 Sep 2007 14:06:19 +0200 | ||
4 | Subject: [PATCH] Correctly segment incoming usock data into packets, handler short reads. | ||
5 | |||
6 | --- | ||
7 | include/gsmd/gsmd.h | 2 ++ | ||
8 | src/gsmd/usock.c | 20 ++++++++++++++++---- | ||
9 | 2 files changed, 18 insertions(+), 4 deletions(-) | ||
10 | |||
11 | diff --git a/include/gsmd/gsmd.h b/include/gsmd/gsmd.h | ||
12 | index 6ac9d8e..acec02a 100644 | ||
13 | --- a/include/gsmd/gsmd.h | ||
14 | +++ b/include/gsmd/gsmd.h | ||
15 | @@ -95,6 +95,8 @@ struct gsmd_user { | ||
16 | struct gsmd *gsmd; | ||
17 | struct gsmd_fd gfd; /* the socket */ | ||
18 | u_int32_t subscriptions; /* bitmaks of subscribed event groups */ | ||
19 | + char usock_fifo[1024]; | ||
20 | + int usock_len; | ||
21 | |||
22 | struct llist_head pb_readrg_list; /* our READRG phonebook list */ | ||
23 | struct llist_head pb_find_list; /* our FIND phonebook list */ | ||
24 | diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c | ||
25 | index 32e98d0..bac5f0c 100644 | ||
26 | --- a/src/gsmd/usock.c | ||
27 | +++ b/src/gsmd/usock.c | ||
28 | @@ -1529,14 +1529,15 @@ static int usock_rcv_pcmd(struct gsmd_user *gu, char *buf, int len) | ||
29 | static int gsmd_usock_user_cb(int fd, unsigned int what, void *data) | ||
30 | { | ||
31 | struct gsmd_user *gu = data; | ||
32 | + struct gsmd_msg_hdr *gph; | ||
33 | |||
34 | /* FIXME: check some kind of backlog and limit it */ | ||
35 | |||
36 | if (what & GSMD_FD_READ) { | ||
37 | - char buf[1024]; | ||
38 | int rcvlen; | ||
39 | /* read data from socket, determine what he wants */ | ||
40 | - rcvlen = read(fd, buf, sizeof(buf)); | ||
41 | + rcvlen = read(fd, gu->usock_fifo + gu->usock_len, | ||
42 | + sizeof(gu->usock_fifo) - gu->usock_len); | ||
43 | if (rcvlen == 0) { | ||
44 | DEBUGP("EOF, this client has just vanished\n"); | ||
45 | /* EOF, this client has just vanished */ | ||
46 | @@ -1549,8 +1550,18 @@ static int gsmd_usock_user_cb(int fd, unsigned int what, void *data) | ||
47 | return 0; | ||
48 | } else if (rcvlen < 0) | ||
49 | return rcvlen; | ||
50 | - else | ||
51 | - return usock_rcv_pcmd(gu, buf, rcvlen); | ||
52 | + | ||
53 | + gu->usock_len += rcvlen; | ||
54 | + gph = (struct gsmd_msg_hdr *) gu->usock_fifo; | ||
55 | + while (gu->usock_len >= sizeof(*gph) && | ||
56 | + gu->usock_len >= sizeof(*gph) + gph->len) { | ||
57 | + usock_rcv_pcmd(gu, gu->usock_fifo, gu->usock_len); | ||
58 | + gu->usock_len -= sizeof(*gph) + gph->len; | ||
59 | + memmove(gu->usock_fifo, | ||
60 | + gu->usock_fifo + sizeof(*gph) + | ||
61 | + gph->len, | ||
62 | + gu->usock_len); | ||
63 | + } | ||
64 | } | ||
65 | |||
66 | if (what & GSMD_FD_WRITE) { | ||
67 | @@ -1609,6 +1620,7 @@ static int gsmd_usock_cb(int fd, unsigned int what, void *data) | ||
68 | newuser->gfd.cb = &gsmd_usock_user_cb; | ||
69 | newuser->gsmd = g; | ||
70 | newuser->subscriptions = 0xffffffff; | ||
71 | + newuser->usock_len = 0; | ||
72 | INIT_LLIST_HEAD(&newuser->finished_ucmds); | ||
73 | INIT_LLIST_HEAD(&newuser->pb_readrg_list); | ||
74 | INIT_LLIST_HEAD(&newuser->pb_find_list); | ||
75 | -- | ||
76 | 1.5.2.1 | ||
77 | |||
diff --git a/meta/packages/libgsmd/files/0004-Handle-read-and-write-return-values.patch b/meta/packages/libgsmd/files/0004-Handle-read-and-write-return-values.patch new file mode 100644 index 0000000000..f5e7a7902d --- /dev/null +++ b/meta/packages/libgsmd/files/0004-Handle-read-and-write-return-values.patch | |||
@@ -0,0 +1,176 @@ | |||
1 | From 421b0fa14fefbd13a455c20380fecddda616b41a Mon Sep 17 00:00:00 2001 | ||
2 | From: Andrzej Zaborowski <balrog@zabor.org> | ||
3 | Date: Wed, 19 Sep 2007 18:30:36 +0200 | ||
4 | Subject: [PATCH] Handle read() and write() return values. | ||
5 | |||
6 | --- | ||
7 | include/libgsmd/libgsmd.h | 3 +- | ||
8 | src/gsmd/usock.c | 38 ++++++++++++++++----------- | ||
9 | src/libgsmd/lgsm_internals.h | 2 + | ||
10 | src/libgsmd/libgsmd.c | 58 ++++++++++++++++++++++++++--------------- | ||
11 | 4 files changed, 63 insertions(+), 38 deletions(-) | ||
12 | |||
13 | diff --git a/include/libgsmd/libgsmd.h b/include/libgsmd/libgsmd.h | ||
14 | index fc56890..db15aa9 100644 | ||
15 | --- a/include/libgsmd/libgsmd.h | ||
16 | +++ b/include/libgsmd/libgsmd.h | ||
17 | @@ -65,6 +65,7 @@ extern int lgsm_subscriptions(struct lgsm_handle *lh, u_int32_t subscriptions); | ||
18 | |||
19 | extern struct gsmd_msg_hdr *lgsm_gmh_fill(int type, int subtype, int payload_len); | ||
20 | extern int lgsm_send(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh); | ||
21 | -extern int lgsm_handle_packet(struct lgsm_handle *lh, char *buf, int len); | ||
22 | +extern int lgsm_handle_packet(struct lgsm_handle *lh, | ||
23 | + const char *buf, int len); | ||
24 | |||
25 | #endif | ||
26 | diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c | ||
27 | index bac5f0c..2283600 100644 | ||
28 | --- a/src/gsmd/usock.c | ||
29 | +++ b/src/gsmd/usock.c | ||
30 | @@ -1569,23 +1569,29 @@ static int gsmd_usock_user_cb(int fd, unsigned int what, void *data) | ||
31 | struct gsmd_ucmd *ucmd, *uctmp; | ||
32 | llist_for_each_entry_safe(ucmd, uctmp, &gu->finished_ucmds, | ||
33 | list) { | ||
34 | - int rc; | ||
35 | - | ||
36 | - rc = write(fd, &ucmd->hdr, sizeof(ucmd->hdr) + ucmd->hdr.len); | ||
37 | - if (rc < 0) { | ||
38 | - DEBUGP("write return %d\n", rc); | ||
39 | - return rc; | ||
40 | - } | ||
41 | - if (rc == 0) { | ||
42 | - DEBUGP("write returns zero!!\n"); | ||
43 | - break; | ||
44 | + const void *pos = &ucmd->hdr; | ||
45 | + size_t len = sizeof(ucmd->hdr) + ucmd->hdr.len; | ||
46 | + | ||
47 | + while (len) { | ||
48 | + ssize_t rc; | ||
49 | + | ||
50 | + rc = write(fd, pos, len); | ||
51 | + if (rc < 0 && errno != EINTR) { | ||
52 | + DEBUGP("write returned %s\n", | ||
53 | + strerror(errno)); | ||
54 | + return rc; | ||
55 | + } | ||
56 | + if (rc == 0 && pos == &ucmd->hdr) { | ||
57 | + DEBUGP("write returns zero!!\n"); | ||
58 | + return 0; | ||
59 | + } | ||
60 | + if (rc > 0) { | ||
61 | + len -= rc; | ||
62 | + pos += rc; | ||
63 | + } | ||
64 | } | ||
65 | - if (rc != sizeof(ucmd->hdr) + ucmd->hdr.len) { | ||
66 | - DEBUGP("short write\n"); | ||
67 | - break; | ||
68 | - } | ||
69 | - | ||
70 | - DEBUGP("successfully sent cmd %p to user %p, freeing\n", ucmd, gu); | ||
71 | + DEBUGP("successfully sent cmd %p to user %p, " | ||
72 | + "freeing\n", ucmd, gu); | ||
73 | llist_del(&ucmd->list); | ||
74 | talloc_free(ucmd); | ||
75 | } | ||
76 | diff --git a/src/libgsmd/lgsm_internals.h b/src/libgsmd/lgsm_internals.h | ||
77 | index c826723..f1b1a23 100644 | ||
78 | --- a/src/libgsmd/lgsm_internals.h | ||
79 | +++ b/src/libgsmd/lgsm_internals.h | ||
80 | @@ -8,6 +8,8 @@ struct lgsm_handle { | ||
81 | int fd; | ||
82 | lgsm_msg_handler *handler[__NUM_GSMD_MSGS]; | ||
83 | enum lgsm_netreg_state netreg_state; | ||
84 | + char usock_fifo[1024]; | ||
85 | + int usock_len; | ||
86 | }; | ||
87 | |||
88 | int lgsm_send(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh); | ||
89 | diff --git a/src/libgsmd/libgsmd.c b/src/libgsmd/libgsmd.c | ||
90 | index 9906ea8..cc804ed 100644 | ||
91 | --- a/src/libgsmd/libgsmd.c | ||
92 | +++ b/src/libgsmd/libgsmd.c | ||
93 | @@ -86,34 +86,37 @@ static int lgsm_open_backend(struct lgsm_handle *lh, const char *device) | ||
94 | } | ||
95 | |||
96 | /* handle a packet that was received on the gsmd socket */ | ||
97 | -int lgsm_handle_packet(struct lgsm_handle *lh, char *buf, int len) | ||
98 | +int lgsm_handle_packet(struct lgsm_handle *lh, const char *buf, int len) | ||
99 | { | ||
100 | struct gsmd_msg_hdr *gmh; | ||
101 | lgsm_msg_handler *handler; | ||
102 | int rc = 0; | ||
103 | |||
104 | - while (len) { | ||
105 | - if (len < sizeof(*gmh)) | ||
106 | - return -EINVAL; | ||
107 | - gmh = (struct gsmd_msg_hdr *) buf; | ||
108 | - | ||
109 | - if (len - sizeof(*gmh) < gmh->len) | ||
110 | - return -EINVAL; | ||
111 | - len -= sizeof(*gmh) + gmh->len; | ||
112 | - buf += sizeof(*gmh) + gmh->len; | ||
113 | - | ||
114 | - if (gmh->msg_type >= __NUM_GSMD_MSGS) | ||
115 | - return -EINVAL; | ||
116 | - | ||
117 | - handler = lh->handler[gmh->msg_type]; | ||
118 | + if (lh->usock_len + len > sizeof(lh->usock_fifo)) | ||
119 | + return -ENOMEM; | ||
120 | |||
121 | - if (handler) | ||
122 | + memcpy(lh->usock_fifo + lh->usock_len, buf, len); | ||
123 | + lh->usock_len += len; | ||
124 | + gmh = (struct gsmd_msg_hdr *) lh->usock_fifo; | ||
125 | + while (lh->usock_len >= sizeof(*gmh) && | ||
126 | + lh->usock_len >= sizeof(*gmh) + gmh->len) { | ||
127 | + if (gmh->msg_type < __NUM_GSMD_MSGS && | ||
128 | + (handler = lh->handler[gmh->msg_type])) | ||
129 | rc |= handler(lh, gmh); | ||
130 | - else | ||
131 | - fprintf(stderr, "unable to handle packet type=%u\n", | ||
132 | - gmh->msg_type); | ||
133 | + else { | ||
134 | + fprintf(stderr, "unable to handle packet " | ||
135 | + "type=%u id=%u\n", | ||
136 | + gmh->msg_type, gmh->id); | ||
137 | + rc |= EINVAL; | ||
138 | + } | ||
139 | + | ||
140 | + lh->usock_len -= gmh->len + sizeof(*gmh); | ||
141 | + memmove(lh->usock_fifo, | ||
142 | + lh->usock_fifo + gmh->len + sizeof(*gmh), | ||
143 | + lh->usock_len); | ||
144 | } | ||
145 | - return rc; | ||
146 | + | ||
147 | + return -rc; | ||
148 | } | ||
149 | |||
150 | int lgsm_register_handler(struct lgsm_handle *lh, int type, lgsm_msg_handler *handler) | ||
151 | @@ -193,8 +196,21 @@ static u_int16_t next_msg_id; | ||
152 | |||
153 | int lgsm_send(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) | ||
154 | { | ||
155 | + ssize_t rc; | ||
156 | + size_t len = sizeof(*gmh) + gmh->len; | ||
157 | + const void *pos = gmh; | ||
158 | + | ||
159 | gmh->id = next_msg_id++; | ||
160 | - return send(lh->fd, (char *) gmh, sizeof(*gmh) + gmh->len, 0); | ||
161 | + while (len) { | ||
162 | + rc = send(lh->fd, pos, len, 0); | ||
163 | + if (rc < 0 && errno != EINTR) | ||
164 | + return -errno; | ||
165 | + if (rc > 0) { | ||
166 | + len -= rc; | ||
167 | + pos += rc; | ||
168 | + } | ||
169 | + } | ||
170 | + return 0; | ||
171 | } | ||
172 | |||
173 | struct gsmd_msg_hdr *lgsm_gmh_fill(int type, int subtype, int payload_len) | ||
174 | -- | ||
175 | 1.5.2.1 | ||
176 | |||
diff --git a/meta/packages/libgsmd/files/0005-Add-ask-ds-option-forSMS.patch b/meta/packages/libgsmd/files/0005-Add-ask-ds-option-forSMS.patch new file mode 100644 index 0000000000..e9f49bd7d2 --- /dev/null +++ b/meta/packages/libgsmd/files/0005-Add-ask-ds-option-forSMS.patch | |||
@@ -0,0 +1,130 @@ | |||
1 | diff --git a/include/gsmd/usock.h b/include/gsmd/usock.h | ||
2 | index 236ad78..66cdf48 100644 | ||
3 | --- a/include/gsmd/usock.h | ||
4 | +++ b/include/gsmd/usock.h | ||
5 | @@ -332,6 +332,7 @@ struct gsmd_sms { | ||
6 | struct gsmd_sms_submit { | ||
7 | struct gsmd_addr addr; | ||
8 | struct gsmd_sms payload; | ||
9 | + int ask_ds; | ||
10 | }; | ||
11 | |||
12 | /* Refer to GSM 07.05 subclause 4.4 */ | ||
13 | diff --git a/include/libgsmd/sms.h b/include/libgsmd/sms.h | ||
14 | index 3ada62d..9808442 100644 | ||
15 | --- a/include/libgsmd/sms.h | ||
16 | +++ b/include/libgsmd/sms.h | ||
17 | @@ -46,6 +46,7 @@ struct lgsm_sms { | ||
18 | enum gsmd_sms_alphabet alpha; | ||
19 | u_int8_t data[LGSM_SMS_DATA_MAXLEN+1]; | ||
20 | int length; | ||
21 | + int ask_ds; | ||
22 | }; | ||
23 | |||
24 | /* GSM 03.40 subclause 9.2.2.2 and GSM 07.05 subclause 4.4 and subclause 3.1 */ | ||
25 | diff --git a/src/gsmd/sms_pdu.c b/src/gsmd/sms_pdu.c | ||
26 | index d1235dd..d461999 100644 | ||
27 | --- a/src/gsmd/sms_pdu.c | ||
28 | +++ b/src/gsmd/sms_pdu.c | ||
29 | @@ -247,7 +247,8 @@ int sms_pdu_make_smssubmit(char *dest, const struct gsmd_sms_submit *src) | ||
30 | GSMD_SMS_TP_MTI_SUBMIT | | ||
31 | (0 << 2) | /* Reject Duplicates: 0 */ | ||
32 | GSMD_SMS_TP_VPF_NOT_PRESENT | | ||
33 | - GSMD_SMS_TP_SRR_STATUS_REQUEST | | ||
34 | + (src->ask_ds ? GSMD_SMS_TP_SRR_STATUS_REQUEST : | ||
35 | + GSMD_SMS_TP_SRR_NOT_REQUEST) | | ||
36 | (src->payload.has_header ? GSMD_SMS_TP_UDHI_WITH_HEADER : | ||
37 | GSMD_SMS_TP_UDHI_NO_HEADER) | | ||
38 | GSMD_SMS_TP_RP_NOT_SET; | ||
39 | diff --git a/src/libgsmd/libgsmd_sms.c b/src/libgsmd/libgsmd_sms.c | ||
40 | index 22d7dbf..bbc8689 100644 | ||
41 | --- a/src/libgsmd/libgsmd_sms.c | ||
42 | +++ b/src/libgsmd/libgsmd_sms.c | ||
43 | @@ -126,6 +126,7 @@ int lgsm_sms_send(struct lgsm_handle *lh, | ||
44 | if (lgsm_number2addr(&gss->addr, sms->addr, 1)) | ||
45 | return -EINVAL; | ||
46 | |||
47 | + gss->ask_ds = sms->ask_ds; | ||
48 | gss->payload.has_header = 0; | ||
49 | gss->payload.length = sms->length; | ||
50 | gss->payload.coding_scheme = sms->alpha; | ||
51 | @@ -161,6 +162,7 @@ int lgsm_sms_write(struct lgsm_handle *lh, | ||
52 | if (lgsm_number2addr(&gsw->sms.addr, sms_write->sms.addr, 1)) | ||
53 | return -EINVAL; | ||
54 | |||
55 | + gsw->sms.ask_ds = sms_write->sms.ask_ds; | ||
56 | gsw->sms.payload.has_header = 0; | ||
57 | gsw->sms.payload.length = sms_write->sms.length; | ||
58 | gsw->sms.payload.coding_scheme = sms_write->sms.alpha; | ||
59 | diff --git a/src/util/shell.c b/src/util/shell.c | ||
60 | index f902126..f26e17e 100644 | ||
61 | --- a/src/util/shell.c | ||
62 | +++ b/src/util/shell.c | ||
63 | @@ -355,7 +355,7 @@ static int shell_help(void) | ||
64 | "\tsd\tSMS Delete (sd=index,delflg)\n" | ||
65 | "\tsl\tSMS List (sl=stat)\n" | ||
66 | "\tsr\tSMS Read (sr=index)\n" | ||
67 | - "\tss\tSMS Send (ss=number,text|[\"text\"])\n" | ||
68 | + "\tss\tSMS Send (ss=ask_ds,number,text|[\"text\"])\n" | ||
69 | "\tsw\tSMS Write (sw=stat,number,text)\n" | ||
70 | "\tsm\tSMS Storage stats\n" | ||
71 | "\tsM\tSMS Set preferred storage (sM=mem1,mem2,mem3)\n" | ||
72 | @@ -563,33 +563,29 @@ int shell_main(struct lgsm_handle *lgsmh) | ||
73 | struct lgsm_sms sms; | ||
74 | |||
75 | ptr = strchr(buf, '='); | ||
76 | + sms.ask_ds = atoi(ptr+1); | ||
77 | fcomma = strchr(buf, ','); | ||
78 | - if (!ptr || !fcomma) { | ||
79 | - printf("Wrong command format\n"); | ||
80 | - } else { | ||
81 | - strncpy(sms.addr, ptr+1, fcomma-ptr-1); | ||
82 | - sms.addr[fcomma-ptr-1] = '\0'; | ||
83 | - | ||
84 | - /* todo define \" to allow " in text */ | ||
85 | - if (fcomma[1] == '"' && | ||
86 | - !strchr(fcomma+2, '"')) { | ||
87 | + lcomma = strchr(fcomma+1, ','); | ||
88 | + strncpy(sms.addr, fcomma+1, lcomma-fcomma-1); | ||
89 | + sms.addr[lcomma-fcomma-1] = '\0'; | ||
90 | + /* todo define \" to allow " in text */ | ||
91 | + if (lcomma[1]=='"' && | ||
92 | + !strchr(lcomma+2, '"')) { | ||
93 | /* read until closing '"' */ | ||
94 | rc = fscanf(stdin, "%[^\"]\"", | ||
95 | - fcomma+strlen(fcomma)); | ||
96 | + lcomma+strlen(lcomma)); | ||
97 | if (rc == EOF) { | ||
98 | printf("EOF\n"); | ||
99 | return -1; | ||
100 | } | ||
101 | /* remove brackets */ | ||
102 | - fcomma++; | ||
103 | - fcomma[strlen(fcomma)] = '\0'; | ||
104 | - } | ||
105 | - | ||
106 | - printf("Send SMS\n"); | ||
107 | - packing_7bit_character(fcomma+1, &sms); | ||
108 | + lcomma++; | ||
109 | + lcomma[strlen(lcomma)] = '\0'; | ||
110 | + } | ||
111 | + printf("Send SMS\n"); | ||
112 | + packing_7bit_character(lcomma+1, &sms); | ||
113 | |||
114 | - lgsm_sms_send(lgsmh, &sms); | ||
115 | - } | ||
116 | + lgsm_sms_send(lgsmh, &sms); | ||
117 | } else if ( !strncmp(buf, "sw", 2)) { | ||
118 | printf("Write SMS\n"); | ||
119 | struct lgsm_sms_write sms_write; | ||
120 | @@ -603,6 +599,7 @@ int shell_main(struct lgsm_handle *lgsmh) | ||
121 | sms_write.sms.addr[lcomma-fcomma-1] = '\0'; | ||
122 | packing_7bit_character( | ||
123 | lcomma+1, &sms_write.sms); | ||
124 | + sms_write.sms.ask_ds = 0; | ||
125 | |||
126 | lgsm_sms_write(lgsmh, &sms_write); | ||
127 | } else if (!strncmp(buf, "sm", 2)) { | ||
128 | -- | ||
129 | 1.5.2.1 | ||
130 | |||
diff --git a/meta/packages/libgsmd/files/024_sms-text-in-bracket.patch b/meta/packages/libgsmd/files/024_sms-text-in-bracket.patch new file mode 100644 index 0000000000..32a1ca33ff --- /dev/null +++ b/meta/packages/libgsmd/files/024_sms-text-in-bracket.patch | |||
@@ -0,0 +1,70 @@ | |||
1 | http://bugzilla.openmoko.org/cgi-bin/bugzilla/show_bug.cgi?id=834 | ||
2 | |||
3 | From: Kristian Mueller <kristian@mput.de> | ||
4 | Subject: [PATCH] libgsmd-tool does not allow sms with more than one word | ||
5 | |||
6 | libgsmd-tool only allows for command strings without spaces. | ||
7 | SMS messages with more than one word will be parsed as multible commands. | ||
8 | The patch introduces SMS message text in bracket and fixes a NULL pointer | ||
9 | reference on mailformed "ss" commands. | ||
10 | |||
11 | Signed-off-by: Jim Huang <jserv@openmoko.org> | ||
12 | --- | ||
13 | src/util/shell.c | 32 ++++++++++++++++++++++++++------ | ||
14 | 1 file changed, 26 insertions(+), 6 deletions(-) | ||
15 | |||
16 | Index: gsm/src/util/shell.c | ||
17 | =================================================================== | ||
18 | --- gsm.orig/src/util/shell.c 2007-08-31 16:15:30.000000000 +0800 | ||
19 | +++ gsm/src/util/shell.c 2007-09-17 23:35:31.000000000 +0800 | ||
20 | @@ -389,7 +389,7 @@ | ||
21 | "\tsd\tSMS Delete (sd=index,delflg)\n" | ||
22 | "\tsl\tSMS List (sl=stat)\n" | ||
23 | "\tsr\tSMS Read (sr=index)\n" | ||
24 | - "\tss\tSMS Send (ss=number,text)\n" | ||
25 | + "\tss\tSMS Send (ss=number,text|[\"text\"])\n" | ||
26 | "\tsw\tSMS Write (sw=stat,number,text)\n" | ||
27 | "\tsm\tSMS Storage stats\n" | ||
28 | "\tsM\tSMS Set preferred storage (sM=mem1,mem2,mem3)\n" | ||
29 | @@ -612,16 +612,36 @@ | ||
30 | |||
31 | lgsm_sms_read(lgsmh, atoi(ptr+1)); | ||
32 | } else if ( !strncmp(buf, "ss", 2)) { | ||
33 | - printf("Send SMS\n"); | ||
34 | struct lgsm_sms sms; | ||
35 | |||
36 | ptr = strchr(buf, '='); | ||
37 | fcomma = strchr(buf, ','); | ||
38 | - strncpy(sms.addr, ptr+1, fcomma-ptr-1); | ||
39 | - sms.addr[fcomma-ptr-1] = '\0'; | ||
40 | - packing_7bit_character(fcomma+1, &sms); | ||
41 | + if (!ptr || !fcomma) { | ||
42 | + printf("Wrong command format\n"); | ||
43 | + } else { | ||
44 | + strncpy(sms.addr, ptr+1, fcomma-ptr-1); | ||
45 | + sms.addr[fcomma-ptr-1] = '\0'; | ||
46 | + | ||
47 | + /* todo define \" to allow " in text */ | ||
48 | + if (fcomma[1] == '"' && | ||
49 | + !strchr(fcomma+2, '"')) { | ||
50 | + /* read until closing '"' */ | ||
51 | + rc = fscanf(stdin, "%[^\"]\"", | ||
52 | + fcomma+strlen(fcomma)); | ||
53 | + if (rc == EOF) { | ||
54 | + printf("EOF\n"); | ||
55 | + return -1; | ||
56 | + } | ||
57 | + /* remove brackets */ | ||
58 | + fcomma++; | ||
59 | + fcomma[strlen(fcomma)] = '\0'; | ||
60 | + } | ||
61 | + | ||
62 | + printf("Send SMS\n"); | ||
63 | + packing_7bit_character(fcomma+1, &sms); | ||
64 | |||
65 | - lgsm_sms_send(lgsmh, &sms); | ||
66 | + lgsm_sms_send(lgsmh, &sms); | ||
67 | + } | ||
68 | } else if ( !strncmp(buf, "sw", 2)) { | ||
69 | printf("Write SMS\n"); | ||
70 | struct lgsm_sms_write sms_write; | ||
diff --git a/meta/packages/libgsmd/files/025_sms-status-report.patch b/meta/packages/libgsmd/files/025_sms-status-report.patch new file mode 100644 index 0000000000..560e72e380 --- /dev/null +++ b/meta/packages/libgsmd/files/025_sms-status-report.patch | |||
@@ -0,0 +1,133 @@ | |||
1 | From: Erin Yueh <erin_yueh@openmoko.com> | ||
2 | Subject: [PATCH] SMS status report | ||
3 | |||
4 | I made a patch for SMS status report. It can change SMS-Submit messages | ||
5 | and ask for a status report. When the destination address receives our | ||
6 | message, the service center will send a SMS-STATUS-REPORT to us. We can | ||
7 | tell what messages we sent by TP-MR (message reference number) value and | ||
8 | can know the sending result by TP-ST (Status) value from status report | ||
9 | messages. | ||
10 | |||
11 | PS. if you don't want to ask a status report, you can change this value | ||
12 | back. Replace "GSMD_SMS_TP_SRR_STATUS_REQUEST" with | ||
13 | "GSMD_SMS_TP_SRR_NOT_REQUEST". | ||
14 | header[pos ++] = | ||
15 | GSMD_SMS_TP_MTI_SUBMIT | | ||
16 | (0 << 2) | /* Reject Duplicates: 0 */ | ||
17 | GSMD_SMS_TP_VPF_NOT_PRESENT | | ||
18 | - GSMD_SMS_TP_SRR_NOT_REQUEST | | ||
19 | + GSMD_SMS_TP_SRR_STATUS_REQUEST | | ||
20 | (src->payload.has_header ? GSMD_SMS_TP_UDHI_WITH_HEADER : | ||
21 | GSMD_SMS_TP_UDHI_NO_HEADER) | | ||
22 | GSMD_SMS_TP_RP_NOT_SET; | ||
23 | |||
24 | Signed-off-by: Jim Huang <jserv@openmoko.org> | ||
25 | --- | ||
26 | src/gsmd/sms_pdu.c | 54 +++++++++++++++++++++++++++++++++++++++++++----------- | ||
27 | src/util/event.c | 6 +++++- | ||
28 | 2 files changed, 48 insertions(+), 12 deletions(-) | ||
29 | |||
30 | Index: gsm/src/gsmd/sms_pdu.c | ||
31 | =================================================================== | ||
32 | --- gsm.orig/src/gsmd/sms_pdu.c 2007-09-06 11:14:34.000000000 +0800 | ||
33 | +++ gsm/src/gsmd/sms_pdu.c 2007-09-17 23:39:20.000000000 +0800 | ||
34 | @@ -139,6 +139,17 @@ | ||
35 | /* Skip TP-PID */ | ||
36 | len -= 9; | ||
37 | src += 9; | ||
38 | + | ||
39 | + /* TP-UDL */ | ||
40 | + dst->payload.length = src[0]; | ||
41 | + i = sms_data_bytelen(dst->payload.coding_scheme, src[0]); | ||
42 | + | ||
43 | + /* TP-UD */ | ||
44 | + if (len < 1 + i || i > GSMD_SMS_DATA_MAXLEN) | ||
45 | + return 1; | ||
46 | + memcpy(dst->payload.data, src + 1, i); | ||
47 | + dst->payload.data[i] = 0; | ||
48 | + | ||
49 | break; | ||
50 | case GSMD_SMS_TP_MTI_SUBMIT: | ||
51 | if (len < 4) | ||
52 | @@ -179,23 +190,44 @@ | ||
53 | src += vpf ? 3 : 2; | ||
54 | |||
55 | memset(dst->time_stamp, 0, 7); | ||
56 | + | ||
57 | + /* TP-UDL */ | ||
58 | + dst->payload.length = src[0]; | ||
59 | + i = sms_data_bytelen(dst->payload.coding_scheme, src[0]); | ||
60 | + | ||
61 | + /* TP-UD */ | ||
62 | + if (len < 1 + i || i > GSMD_SMS_DATA_MAXLEN) | ||
63 | + return 1; | ||
64 | + memcpy(dst->payload.data, src + 1, i); | ||
65 | + dst->payload.data[i] = 0; | ||
66 | break; | ||
67 | case GSMD_SMS_TP_MTI_STATUS_REPORT: | ||
68 | - /* TODO */ | ||
69 | + if (len < 3) | ||
70 | + return 1; | ||
71 | + | ||
72 | + /* TP-MR set it gsmd_sms_list.index*/ | ||
73 | + dst->index = (int) src[1]; | ||
74 | + /* TP-STATUS set it to coding_scheme */ | ||
75 | + dst->payload.coding_scheme = (int) src[len-1]; | ||
76 | + /* TP-RA */ | ||
77 | + i = sms_number_bytelen(src[3], src[2]); | ||
78 | + if (len < 13 + i) | ||
79 | + return 1; | ||
80 | + if (sms_address2ascii(&dst->addr, src + 2)) | ||
81 | + return 1; | ||
82 | + len -= 4 + i; | ||
83 | + src += 4 + i; | ||
84 | + /* TP-SCTS */ | ||
85 | + memcpy(dst->time_stamp, src, 7); | ||
86 | + /* TP-UD */ | ||
87 | + dst->payload.length = 0; | ||
88 | + dst->payload.data[0] = 0; | ||
89 | + break; | ||
90 | default: | ||
91 | /* Unknown PDU type */ | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | - /* TP-UDL */ | ||
96 | - dst->payload.length = src[0]; | ||
97 | - i = sms_data_bytelen(dst->payload.coding_scheme, src[0]); | ||
98 | - | ||
99 | - /* TP-UD */ | ||
100 | - if (len < 1 + i || i > GSMD_SMS_DATA_MAXLEN) | ||
101 | - return 1; | ||
102 | - memcpy(dst->payload.data, src + 1, i); | ||
103 | - dst->payload.data[i] = 0; | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | @@ -215,7 +247,7 @@ | ||
108 | GSMD_SMS_TP_MTI_SUBMIT | | ||
109 | (0 << 2) | /* Reject Duplicates: 0 */ | ||
110 | GSMD_SMS_TP_VPF_NOT_PRESENT | | ||
111 | - GSMD_SMS_TP_SRR_NOT_REQUEST | | ||
112 | + GSMD_SMS_TP_SRR_STATUS_REQUEST | | ||
113 | (src->payload.has_header ? GSMD_SMS_TP_UDHI_WITH_HEADER : | ||
114 | GSMD_SMS_TP_UDHI_NO_HEADER) | | ||
115 | GSMD_SMS_TP_RP_NOT_SET; | ||
116 | Index: gsm/src/util/event.c | ||
117 | =================================================================== | ||
118 | --- gsm.orig/src/util/event.c 2007-09-06 11:14:34.000000000 +0800 | ||
119 | +++ gsm/src/util/event.c 2007-09-17 23:39:47.000000000 +0800 | ||
120 | @@ -128,8 +128,12 @@ | ||
121 | static int inds_handler(struct lgsm_handle *lh, int evt, | ||
122 | struct gsmd_evt_auxdata *aux) | ||
123 | { | ||
124 | - if (aux->u.ds.inlined) | ||
125 | + if (aux->u.ds.inlined) { | ||
126 | + struct gsmd_sms_list *sms; | ||
127 | + sms = (struct gsmd_sms_list *) aux->data; | ||
128 | printf("EVENT: Incoming Status Report\n"); | ||
129 | + printf("message ref = %d, status = %d\n", sms->index,sms->payload.coding_scheme); | ||
130 | + } | ||
131 | else | ||
132 | printf("EVENT: Incoming Status Report stored at location %i\n", | ||
133 | aux->u.ds.index); | ||
diff --git a/meta/packages/libgsmd/files/027_phonebook-find-and-read-range-support.patch b/meta/packages/libgsmd/files/027_phonebook-find-and-read-range-support.patch new file mode 100644 index 0000000000..ea0f12daac --- /dev/null +++ b/meta/packages/libgsmd/files/027_phonebook-find-and-read-range-support.patch | |||
@@ -0,0 +1,423 @@ | |||
1 | From: Sean Chiang <sean_chiang@openmoko.com> | ||
2 | Subject: [PATCH] Improvement for find and read phonebooks in gsmd | ||
3 | |||
4 | This patch is an improvement for find and read phonebooks. | ||
5 | After clients make a request to find / read phonebooks, then clients | ||
6 | should make a request to retrieve all the records. | ||
7 | |||
8 | Signed-off-by: Jim Huang <jserv@openmoko.org> | ||
9 | --- | ||
10 | include/gsmd/gsmd.h | 3 | ||
11 | include/gsmd/usock.h | 20 +++- | ||
12 | include/libgsmd/phonebook.h | 6 + | ||
13 | src/gsmd/usock.c | 184 +++++++++++++++++++++++++++++++++++----- | ||
14 | src/libgsmd/libgsmd_phonebook.c | 48 ++++++++++ | ||
15 | 5 files changed, 238 insertions(+), 23 deletions(-) | ||
16 | |||
17 | Index: gsm/include/libgsmd/phonebook.h | ||
18 | =================================================================== | ||
19 | --- gsm.orig/include/libgsmd/phonebook.h 2007-08-31 16:15:29.000000000 +0800 | ||
20 | +++ gsm/include/libgsmd/phonebook.h 2007-09-17 23:48:41.000000000 +0800 | ||
21 | @@ -106,4 +106,10 @@ | ||
22 | /* Get the location range/nlength/tlength supported */ | ||
23 | extern int lgsm_pb_get_support(struct lgsm_handle *lh); | ||
24 | |||
25 | +/* Retrieve the records of READRG request */ | ||
26 | +extern int lgsm_pb_retrieve_readrg(struct lgsm_handle *lh, int num); | ||
27 | + | ||
28 | +/* Retrieve the records of FIND request */ | ||
29 | +extern int lgsm_pb_retrieve_find(struct lgsm_handle *lh, int num); | ||
30 | + | ||
31 | #endif | ||
32 | Index: gsm/include/gsmd/gsmd.h | ||
33 | =================================================================== | ||
34 | --- gsm.orig/include/gsmd/gsmd.h 2007-08-31 16:15:29.000000000 +0800 | ||
35 | +++ gsm/include/gsmd/gsmd.h 2007-09-17 23:48:41.000000000 +0800 | ||
36 | @@ -92,6 +92,9 @@ | ||
37 | struct gsmd *gsmd; | ||
38 | struct gsmd_fd gfd; /* the socket */ | ||
39 | u_int32_t subscriptions; /* bitmaks of subscribed event groups */ | ||
40 | + | ||
41 | + struct llist_head pb_readrg_list; /* our READRG phonebook list */ | ||
42 | + struct llist_head pb_find_list; /* our FIND phonebook list */ | ||
43 | }; | ||
44 | |||
45 | #define GSMD_DEBUG 1 /* debugging information */ | ||
46 | Index: gsm/include/gsmd/usock.h | ||
47 | =================================================================== | ||
48 | --- gsm.orig/include/gsmd/usock.h 2007-08-31 16:15:29.000000000 +0800 | ||
49 | +++ gsm/include/gsmd/usock.h 2007-09-17 23:48:56.000000000 +0800 | ||
50 | @@ -194,6 +194,8 @@ | ||
51 | GSMD_PHONEBOOK_GET_SUPPORT = 6, | ||
52 | GSMD_PHONEBOOK_LIST_STORAGE = 7, | ||
53 | GSMD_PHONEBOOK_SET_STORAGE = 8, | ||
54 | + GSMD_PHONEBOOK_RETRIEVE_READRG = 9, | ||
55 | + GSMD_PHONEBOOK_RETRIEVE_FIND = 10, | ||
56 | }; | ||
57 | |||
58 | /* Type-of-Address, Numbering-Plan-Identification field, GSM 03.40, 9.1.2.5 */ | ||
59 | @@ -431,7 +433,6 @@ | ||
60 | char text[GSMD_PB_TEXT_MAXLEN+1]; | ||
61 | } __attribute__ ((packed)); | ||
62 | |||
63 | - | ||
64 | /* Refer to GSM 07.07 subclause 8.13 */ | ||
65 | /* FIXME: the tlength depends on SIM, use +CPBR=? to get */ | ||
66 | struct gsmd_phonebook_find { | ||
67 | @@ -471,8 +472,18 @@ | ||
68 | char opname_longalpha[16]; | ||
69 | }; | ||
70 | |||
71 | +/* Refer to GSM 07.07 subclause 8.11 */ | ||
72 | +struct gsmd_phonebook_mem { | ||
73 | + u_int8_t type[3]; | ||
74 | + u_int8_t pad; | ||
75 | + u_int16_t used; | ||
76 | + u_int16_t total; | ||
77 | +} __attribute__ ((packed)); | ||
78 | + | ||
79 | struct gsmd_phonebook_storage { | ||
80 | - char storage[3]; | ||
81 | + /* FIXME the amount of phonebook storage should be dynamic */ | ||
82 | + u_int8_t num; | ||
83 | + struct gsmd_phonebook_mem mem[20]; | ||
84 | } __attribute__ ((packed)); | ||
85 | |||
86 | /* Subscriber number information from 3GPP TS 07.07, Clause 7.1 */ | ||
87 | @@ -517,6 +528,11 @@ | ||
88 | char buf[]; | ||
89 | } __attribute__ ((packed)); | ||
90 | |||
91 | +struct gsmd_phonebooks { | ||
92 | + struct llist_head list; | ||
93 | + struct gsmd_phonebook pb; | ||
94 | +} __attribute__ ((packed)); | ||
95 | + | ||
96 | extern struct gsmd_ucmd *ucmd_alloc(int extra_size); | ||
97 | extern int usock_init(struct gsmd *g); | ||
98 | extern void usock_cmd_enqueue(struct gsmd_ucmd *ucmd, struct gsmd_user *gu); | ||
99 | Index: gsm/src/libgsmd/libgsmd_phonebook.c | ||
100 | =================================================================== | ||
101 | --- gsm.orig/src/libgsmd/libgsmd_phonebook.c 2007-08-31 16:15:29.000000000 +0800 | ||
102 | +++ gsm/src/libgsmd/libgsmd_phonebook.c 2007-09-17 23:48:41.000000000 +0800 | ||
103 | @@ -33,7 +33,7 @@ | ||
104 | gmh->data[2] = '\0'; | ||
105 | |||
106 | rc = lgsm_send(lh, gmh); | ||
107 | - if (rc < gmh->len + 3) { | ||
108 | + if (rc < gmh->len + sizeof(*gmh)) { | ||
109 | lgsm_gmh_free(gmh); | ||
110 | return -EIO; | ||
111 | } | ||
112 | @@ -177,3 +177,49 @@ | ||
113 | { | ||
114 | return lgsm_send_simple(lh, GSMD_MSG_PHONEBOOK, GSMD_PHONEBOOK_GET_SUPPORT); | ||
115 | } | ||
116 | + | ||
117 | +int lgsm_pb_retrieve_readrg(struct lgsm_handle *lh, int num) | ||
118 | +{ | ||
119 | + struct gsmd_msg_hdr *gmh; | ||
120 | + int rc; | ||
121 | + | ||
122 | + gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK, | ||
123 | + GSMD_PHONEBOOK_RETRIEVE_READRG, sizeof(int)); | ||
124 | + if (!gmh) | ||
125 | + return -ENOMEM; | ||
126 | + | ||
127 | + *(int *)(gmh->data) = num; | ||
128 | + | ||
129 | + rc = lgsm_send(lh, gmh); | ||
130 | + if (rc < gmh->len + sizeof(*gmh)) { | ||
131 | + lgsm_gmh_free(gmh); | ||
132 | + return -EIO; | ||
133 | + } | ||
134 | + | ||
135 | + lgsm_gmh_free(gmh); | ||
136 | + | ||
137 | + return 0; | ||
138 | +} | ||
139 | + | ||
140 | +int lgsm_pb_retrieve_find(struct lgsm_handle *lh, int num) | ||
141 | +{ | ||
142 | + struct gsmd_msg_hdr *gmh; | ||
143 | + int rc; | ||
144 | + | ||
145 | + gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK, | ||
146 | + GSMD_PHONEBOOK_RETRIEVE_FIND, sizeof(int)); | ||
147 | + if (!gmh) | ||
148 | + return -ENOMEM; | ||
149 | + | ||
150 | + *(int *)(gmh->data) = num; | ||
151 | + | ||
152 | + rc = lgsm_send(lh, gmh); | ||
153 | + if (rc < gmh->len + sizeof(*gmh)) { | ||
154 | + lgsm_gmh_free(gmh); | ||
155 | + return -EIO; | ||
156 | + } | ||
157 | + | ||
158 | + lgsm_gmh_free(gmh); | ||
159 | + | ||
160 | + return 0; | ||
161 | +} | ||
162 | Index: gsm/src/gsmd/usock.c | ||
163 | =================================================================== | ||
164 | --- gsm.orig/src/gsmd/usock.c 2007-08-31 16:15:30.000000000 +0800 | ||
165 | +++ gsm/src/gsmd/usock.c 2007-09-17 23:53:34.000000000 +0800 | ||
166 | @@ -1035,21 +1035,56 @@ | ||
167 | |||
168 | static int phonebook_find_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) | ||
169 | { | ||
170 | - struct gsmd_user *gu = ctx; | ||
171 | - struct gsmd_ucmd *ucmd; | ||
172 | - | ||
173 | + struct gsmd_user *gu = ctx; | ||
174 | + struct gsmd_ucmd *ucmd; | ||
175 | + struct gsmd_phonebooks *gps; | ||
176 | + char *fcomma, *lcomma, *ptr1, *ptr2 = NULL; | ||
177 | + int *num; | ||
178 | + | ||
179 | DEBUGP("resp: %s\n", resp); | ||
180 | |||
181 | - /* FIXME: using link list, also we need to handle the case of | ||
182 | - * no query result */ | ||
183 | - ucmd = gsmd_ucmd_fill(strlen(resp) + 1, GSMD_MSG_PHONEBOOK, | ||
184 | + /* | ||
185 | + * [+CPBF: <index1>,<number>,<type>,<text>[[...] | ||
186 | + * <CR><LF>+CPBF: <index2>,<unmber>,<type>,<text>]] | ||
187 | + */ | ||
188 | + ucmd = gsmd_ucmd_fill(sizeof(int), GSMD_MSG_PHONEBOOK, | ||
189 | GSMD_PHONEBOOK_FIND, 0); | ||
190 | if (!ucmd) | ||
191 | return -ENOMEM; | ||
192 | |||
193 | - strcpy(ucmd->buf, resp); | ||
194 | + num = (int*) ucmd->buf; | ||
195 | + | ||
196 | + *num = 0; | ||
197 | + | ||
198 | + ptr1 = strtok(resp, "\n"); | ||
199 | + | ||
200 | + while (ptr1) { | ||
201 | + gps = (struct gsmd_phonebooks *) malloc(sizeof(struct gsmd_phonebooks)); | ||
202 | + ptr2 = strchr(ptr1, ' '); | ||
203 | + gps->pb.index = atoi(ptr2+1); | ||
204 | + | ||
205 | + fcomma = strchr(ptr1, '"'); | ||
206 | + lcomma = strchr(fcomma+1, '"'); | ||
207 | + strncpy(gps->pb.numb, fcomma + 1, (lcomma-fcomma-1)); | ||
208 | + gps->pb.numb[(lcomma - fcomma) - 1] = '\0'; | ||
209 | + | ||
210 | + gps->pb.type = atoi(lcomma + 2); | ||
211 | + | ||
212 | + ptr2 = strrchr(ptr1, ','); | ||
213 | + fcomma = ptr2 + 1; | ||
214 | + lcomma = strchr(fcomma + 1, '"'); | ||
215 | + strncpy(gps->pb.text, fcomma + 1, (lcomma - fcomma - 1)); | ||
216 | + gps->pb.text[(lcomma - fcomma) - 1] = '\0'; | ||
217 | + | ||
218 | + llist_add_tail(&gps->list, &gu->pb_find_list); | ||
219 | + | ||
220 | + (*num)++; | ||
221 | + | ||
222 | + ptr1 = strtok(NULL, "\n"); | ||
223 | + } | ||
224 | |||
225 | usock_cmd_enqueue(ucmd, gu); | ||
226 | + | ||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | @@ -1102,22 +1137,51 @@ | ||
231 | { | ||
232 | struct gsmd_user *gu = ctx; | ||
233 | struct gsmd_ucmd *ucmd; | ||
234 | + struct gsmd_phonebooks *gps; | ||
235 | + char *fcomma, *lcomma, *ptr1, *ptr2 = NULL; | ||
236 | + int *num; | ||
237 | |||
238 | DEBUGP("resp: %s\n", resp); | ||
239 | |||
240 | /* | ||
241 | - * +CPBR: 4,"1234",129,"6C5F745E7965" | ||
242 | - * +CPBR: 5,"5678",129,"800062115BB6" | ||
243 | - * +CPBR: 6,"7890",129,"810280AA591A" | ||
244 | - * +CPBR: 8,"36874",129,"005300650061006E" | ||
245 | - * | ||
246 | + * [+CPBR: <index1>,<number>,<type>,<text>[[...] | ||
247 | + * <CR><LF>+CPBR: <index2>,<unmber>,<type>,<text>]] | ||
248 | */ | ||
249 | - ucmd = gsmd_ucmd_fill(strlen(resp)+1, GSMD_MSG_PHONEBOOK, | ||
250 | + ucmd = gsmd_ucmd_fill(sizeof(int), GSMD_MSG_PHONEBOOK, | ||
251 | GSMD_PHONEBOOK_READRG, 0); | ||
252 | if (!ucmd) | ||
253 | return -ENOMEM; | ||
254 | |||
255 | - strcpy(ucmd->buf, resp); | ||
256 | + num = (int*) ucmd->buf; | ||
257 | + | ||
258 | + *num = 0; | ||
259 | + | ||
260 | + ptr1 = strtok(resp, "\n"); | ||
261 | + | ||
262 | + while(ptr1) { | ||
263 | + gps = (struct gsmd_phonebooks *) malloc(sizeof(struct gsmd_phonebooks)); | ||
264 | + ptr2 = strchr(ptr1, ' '); | ||
265 | + gps->pb.index = atoi(ptr2+1); | ||
266 | + | ||
267 | + fcomma = strchr(ptr1, '"'); | ||
268 | + lcomma = strchr(fcomma+1, '"'); | ||
269 | + strncpy(gps->pb.numb, fcomma + 1, (lcomma-fcomma-1)); | ||
270 | + gps->pb.numb[(lcomma - fcomma) - 1] = '\0'; | ||
271 | + | ||
272 | + gps->pb.type = atoi(lcomma + 2); | ||
273 | + | ||
274 | + ptr2 = strrchr(ptr1, ','); | ||
275 | + fcomma = ptr2 + 1; | ||
276 | + lcomma = strchr(fcomma + 1, '"'); | ||
277 | + strncpy(gps->pb.text, fcomma + 1, (lcomma - fcomma - 1)); | ||
278 | + gps->pb.text[(lcomma - fcomma) - 1] = '\0'; | ||
279 | + | ||
280 | + llist_add_tail(&gps->list, &gu->pb_readrg_list); | ||
281 | + | ||
282 | + (*num)++; | ||
283 | + | ||
284 | + ptr1 = strtok(NULL, "\n"); | ||
285 | + } | ||
286 | |||
287 | usock_cmd_enqueue(ucmd, gu); | ||
288 | |||
289 | @@ -1209,22 +1273,38 @@ | ||
290 | static int phonebook_list_storage_cb(struct gsmd_atcmd *cmd, | ||
291 | void *ctx, char *resp) | ||
292 | { | ||
293 | - /* +CPBS: ("EN","BD","FD","DC","LD","RC","LR","MT","AD", | ||
294 | - * "SM","SD","MC","LM","AF","ON","UD") */ | ||
295 | /* TODO; using link list ; need to handle command error */ | ||
296 | struct gsmd_user *gu = ctx; | ||
297 | struct gsmd_ucmd *ucmd; | ||
298 | + struct gsmd_phonebook_storage *gps; | ||
299 | + char *ptr; | ||
300 | |||
301 | DEBUGP("resp: %s\n", resp); | ||
302 | |||
303 | - ucmd = gsmd_ucmd_fill(strlen(resp) + 1, | ||
304 | + /* | ||
305 | + * +CPBS: (<storage>s) | ||
306 | + */ | ||
307 | + | ||
308 | + ucmd = gsmd_ucmd_fill(sizeof(*gps), | ||
309 | GSMD_MSG_PHONEBOOK, | ||
310 | GSMD_PHONEBOOK_LIST_STORAGE, 0); | ||
311 | |||
312 | if (!ucmd) | ||
313 | return -ENOMEM; | ||
314 | |||
315 | - strcpy(ucmd->buf, resp); | ||
316 | + gps = (struct gsmd_phonebook_storage *) ucmd->buf; | ||
317 | + gps->num = 0; | ||
318 | + | ||
319 | + if (!strncmp(resp, "+CPBS", 5)) { | ||
320 | + char* delim = "(,"; | ||
321 | + ptr = strpbrk(resp, delim); | ||
322 | + while ( ptr ) { | ||
323 | + strncpy(gps->mem[gps->num].type, ptr+2, 2); | ||
324 | + gps->mem[gps->num].type[2] = '\0'; | ||
325 | + ptr = strpbrk(ptr+2, delim); | ||
326 | + gps->num++; | ||
327 | + } | ||
328 | + } | ||
329 | |||
330 | usock_cmd_enqueue(ucmd, gu); | ||
331 | |||
332 | @@ -1235,11 +1315,13 @@ | ||
333 | struct gsmd_msg_hdr *gph,int len) | ||
334 | { | ||
335 | struct gsmd_atcmd *cmd = NULL; | ||
336 | + struct gsmd_ucmd *ucmd = NULL; | ||
337 | struct gsmd_phonebook_readrg *gpr; | ||
338 | struct gsmd_phonebook *gp; | ||
339 | struct gsmd_phonebook_find *gpf; | ||
340 | - int *index; | ||
341 | - int atcmd_len; | ||
342 | + struct gsmd_phonebooks *cur, *cur2; | ||
343 | + int *index, *num; | ||
344 | + int atcmd_len, i; | ||
345 | char *storage; | ||
346 | char buf[1024]; | ||
347 | |||
348 | @@ -1343,6 +1425,66 @@ | ||
349 | cmd = atcmd_fill("AT+CPBR=?", 9+1, | ||
350 | &phonebook_get_support_cb, gu, gph->id); | ||
351 | break; | ||
352 | + case GSMD_PHONEBOOK_RETRIEVE_READRG: | ||
353 | + if (len < sizeof(*gph) + sizeof(int)) | ||
354 | + return -EINVAL; | ||
355 | + | ||
356 | + num = (int *) ((void *)gph + sizeof(*gph)); | ||
357 | + | ||
358 | + ucmd = gsmd_ucmd_fill(sizeof(struct gsmd_phonebook)*(*num), | ||
359 | + GSMD_MSG_PHONEBOOK, | ||
360 | + GSMD_PHONEBOOK_RETRIEVE_READRG, 0); | ||
361 | + if (!ucmd) | ||
362 | + return -ENOMEM; | ||
363 | + | ||
364 | + gp = (struct gsmd_phonebook*) ucmd->buf; | ||
365 | + | ||
366 | + if (!llist_empty(&gu->pb_readrg_list)) { | ||
367 | + | ||
368 | + llist_for_each_entry_safe(cur, cur2, | ||
369 | + &gu->pb_readrg_list, list) { | ||
370 | + gp->index = cur->pb.index; | ||
371 | + strcpy(gp->numb, cur->pb.numb); | ||
372 | + gp->type = cur->pb.type; | ||
373 | + strcpy(gp->text, cur->pb.text); | ||
374 | + gp++; | ||
375 | + | ||
376 | + llist_del(&cur->list); | ||
377 | + free(cur); | ||
378 | + } | ||
379 | + } | ||
380 | + | ||
381 | + usock_cmd_enqueue(ucmd, gu); | ||
382 | + | ||
383 | + break; | ||
384 | + case GSMD_PHONEBOOK_RETRIEVE_FIND: | ||
385 | + if (len < sizeof(*gph) + sizeof(int)) | ||
386 | + return -EINVAL; | ||
387 | + | ||
388 | + num = (int *) ((void *)gph + sizeof(*gph)); | ||
389 | + | ||
390 | + ucmd = gsmd_ucmd_fill(sizeof(struct gsmd_phonebook)*(*num), GSMD_MSG_PHONEBOOK, | ||
391 | + GSMD_PHONEBOOK_RETRIEVE_FIND, 0); | ||
392 | + if (!ucmd) | ||
393 | + return -ENOMEM; | ||
394 | + | ||
395 | + gp = (struct gsmd_phonebook*) ucmd->buf; | ||
396 | + | ||
397 | + if (!llist_empty(&gu->pb_find_list)) { | ||
398 | + llist_for_each_entry_safe(cur, cur2, &gu->pb_find_list, list) { | ||
399 | + gp->index = cur->pb.index; | ||
400 | + strcpy(gp->numb, cur->pb.numb); | ||
401 | + gp->type = cur->pb.type; | ||
402 | + strcpy(gp->text, cur->pb.text); | ||
403 | + gp++; | ||
404 | + | ||
405 | + llist_del(&cur->list); | ||
406 | + free(cur); | ||
407 | + } | ||
408 | + } | ||
409 | + | ||
410 | + usock_cmd_enqueue(ucmd, gu); | ||
411 | + break; | ||
412 | default: | ||
413 | return -EINVAL; | ||
414 | } | ||
415 | @@ -1468,6 +1610,8 @@ | ||
416 | newuser->gsmd = g; | ||
417 | newuser->subscriptions = 0xffffffff; | ||
418 | INIT_LLIST_HEAD(&newuser->finished_ucmds); | ||
419 | + INIT_LLIST_HEAD(&newuser->pb_readrg_list); | ||
420 | + INIT_LLIST_HEAD(&newuser->pb_find_list); | ||
421 | |||
422 | llist_add(&newuser->list, &g->users); | ||
423 | gsmd_register_fd(&newuser->gfd); | ||
diff --git a/meta/packages/libgsmd/files/028_shell-phonebook-find-and-read-range-support.patch b/meta/packages/libgsmd/files/028_shell-phonebook-find-and-read-range-support.patch new file mode 100644 index 0000000000..db07a5df35 --- /dev/null +++ b/meta/packages/libgsmd/files/028_shell-phonebook-find-and-read-range-support.patch | |||
@@ -0,0 +1,264 @@ | |||
1 | From: Sean Chiang <sean_chiang@openmoko.com> | ||
2 | Subject: [PATCH] improvement for find and read phonebooks in shell | ||
3 | |||
4 | This patch improves the functions to find and read phonebooks in shell. | ||
5 | |||
6 | Besides prr and pf, I add two new commands pRr and pRf to retrieve the | ||
7 | phonebook. | ||
8 | |||
9 | Signed-off-by: Jim Huang <jserv@openmoko.org> | ||
10 | |||
11 | Index: gsm/src/util/shell.c | ||
12 | =================================================================== | ||
13 | --- gsm.orig/src/util/shell.c 2007-09-17 23:57:51.000000000 +0800 | ||
14 | +++ gsm/src/util/shell.c 2007-09-17 23:59:04.000000000 +0800 | ||
15 | @@ -34,8 +34,6 @@ | ||
16 | #include <gsmd/usock.h> | ||
17 | #include <gsmd/ts0705.h> | ||
18 | |||
19 | -#include <common/linux_list.h> | ||
20 | - | ||
21 | #ifndef __GSMD__ | ||
22 | #define __GSMD__ | ||
23 | #include <gsmd/talloc.h> | ||
24 | @@ -43,9 +41,8 @@ | ||
25 | #endif | ||
26 | |||
27 | #define STDIN_BUF_SIZE 1024 | ||
28 | - | ||
29 | -static LLIST_HEAD(storage_list); | ||
30 | -static LLIST_HEAD(phonebook_list); | ||
31 | +static int nFIND = 0; | ||
32 | +static int nREADRG = 0; | ||
33 | |||
34 | /* this is the handler for receiving passthrough responses */ | ||
35 | static int pt_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) | ||
36 | @@ -62,46 +59,23 @@ | ||
37 | struct gsmd_phonebook_storage *gpst; | ||
38 | char *payload; | ||
39 | char *fcomma, *lcomma, *ptr = NULL; | ||
40 | + int *num; | ||
41 | char buf[128]; | ||
42 | + int i; | ||
43 | |||
44 | switch (gmh->msg_subtype) { | ||
45 | -#if 0 | ||
46 | case GSMD_PHONEBOOK_FIND: | ||
47 | + num = (int *) ((char *)gmh + sizeof(*gmh)); | ||
48 | + printf("Records:%d\n", *num); | ||
49 | + | ||
50 | + nFIND = *num; | ||
51 | + break; | ||
52 | case GSMD_PHONEBOOK_READRG: | ||
53 | - payload = (char *)gmh + sizeof(*gmh); | ||
54 | + num = (int *) ((char *)gmh + sizeof(*gmh)); | ||
55 | + printf("Records:%d\n", *num); | ||
56 | |||
57 | - if (!strncmp(payload, "+CPBR", 5) || | ||
58 | - !strncmp(payload, "+CPBF", 5)) { | ||
59 | - gp = (struct gsmd_phonebook *) malloc(sizeof(struct gsmd_phonebook)); | ||
60 | - ptr = strchr(payload, ' '); | ||
61 | - gp->index = atoi(ptr+1); | ||
62 | - | ||
63 | - fcomma = strchr(payload, '"'); | ||
64 | - lcomma = strchr(fcomma+1, '"'); | ||
65 | - strncpy(gp->numb, fcomma + 1, (lcomma-fcomma-1)); | ||
66 | - gp->numb[(lcomma - fcomma) - 1] = '\0'; | ||
67 | - | ||
68 | - gp->type = atoi(lcomma + 2); | ||
69 | - | ||
70 | - ptr = strrchr(payload, ','); | ||
71 | - fcomma = ptr + 1; | ||
72 | - lcomma = strchr(fcomma + 1, '"'); | ||
73 | - strncpy(gp->text, fcomma + 1, (lcomma - fcomma - 1)); | ||
74 | - gp->text[(lcomma - fcomma) - 1] = '\0'; | ||
75 | - | ||
76 | - llist_add_tail(&gp->list, &phonebook_list); | ||
77 | - | ||
78 | -#if 0 | ||
79 | - llist_for_each_entry(gp, &phonebook_list, list) { | ||
80 | - printf("%d, %s, %d, %s\n", gp->index, gp->numb, gp->type, gp->text); | ||
81 | - } | ||
82 | -#endif | ||
83 | - printf("%d, %s, %d, %s\n", gp->index, gp->numb, gp->type, gp->text); | ||
84 | - } | ||
85 | - else | ||
86 | - printf("%s\n", payload); | ||
87 | + nREADRG = *num; | ||
88 | break; | ||
89 | -#endif | ||
90 | case GSMD_PHONEBOOK_READ: | ||
91 | gp = (struct gsmd_phonebook *) ((char *)gmh + sizeof(*gmh)); | ||
92 | if (gp->index) | ||
93 | @@ -115,48 +89,18 @@ | ||
94 | gps = (struct gsmd_phonebook_support *) ((char *)gmh + sizeof(*gmh)); | ||
95 | printf("(1-%d), %d, %d\n", gps->index, gps->nlength, gps->tlength); | ||
96 | break; | ||
97 | -#if 0 | ||
98 | - case GSMD_PHONEBOOK_LIST_STORAGE: | ||
99 | - payload = (char *)gmh + sizeof(*gmh); | ||
100 | |||
101 | - if (!strncmp(payload, "+CPBS", 5)) { | ||
102 | - char* delim = "(,"; | ||
103 | - struct gsmd_phonebook_storage *cur, *cur2; | ||
104 | - | ||
105 | - /* Remove previous record */ | ||
106 | - if (!llist_empty(&storage_list)) { | ||
107 | - llist_for_each_entry_safe(cur, cur2, | ||
108 | - &storage_list, list) { | ||
109 | - llist_del(&cur->list); | ||
110 | - talloc_free(cur); | ||
111 | - } | ||
112 | - } | ||
113 | - | ||
114 | - ptr = strpbrk(payload, delim); | ||
115 | - | ||
116 | - while ( ptr ) { | ||
117 | - gpst = (struct gsmd_phonebook_storage *) malloc(sizeof(struct gsmd_phonebook_storage)); | ||
118 | - strncpy(gpst->storage, ptr+2, 2); | ||
119 | - gpst->storage[2] = '\0'; | ||
120 | - | ||
121 | - ptr = strpbrk(ptr+2, delim); | ||
122 | - | ||
123 | - llist_add_tail(&gpst->list, &storage_list); | ||
124 | - } | ||
125 | + case GSMD_PHONEBOOK_LIST_STORAGE: | ||
126 | + gpst = (struct gsmd_phonebook_storage *)((char *)gmh + sizeof(*gmh)); | ||
127 | |||
128 | - if (llist_empty(&storage_list)) | ||
129 | - return 0; | ||
130 | + for (i = 0; i < gpst->num; i++) { | ||
131 | + printf("%s, ", gpst->mem[i].type); | ||
132 | + } | ||
133 | |||
134 | - llist_for_each_entry(cur, &storage_list, list) { | ||
135 | - printf("\n%s",cur->storage); | ||
136 | - } | ||
137 | + printf("\n"); | ||
138 | |||
139 | - printf("\n"); | ||
140 | - } | ||
141 | - else | ||
142 | - printf("%s\n", payload); | ||
143 | break; | ||
144 | -#endif | ||
145 | + | ||
146 | case GSMD_PHONEBOOK_WRITE: | ||
147 | case GSMD_PHONEBOOK_DELETE: | ||
148 | case GSMD_PHONEBOOK_SET_STORAGE: | ||
149 | @@ -164,6 +108,26 @@ | ||
150 | payload = (char *)gmh + sizeof(*gmh); | ||
151 | printf("%s\n", payload); | ||
152 | break; | ||
153 | + case GSMD_PHONEBOOK_RETRIEVE_READRG: | ||
154 | + gp = (struct gsmd_phonebook *) ((char *)gmh + sizeof(*gmh)); | ||
155 | + | ||
156 | + for (i=0; i<nREADRG; i++) { | ||
157 | + printf("%d,%s,%d,%s\n", gp->index, gp->numb, gp->type, gp->text); | ||
158 | + gp++; | ||
159 | + } | ||
160 | + | ||
161 | + nREADRG = 0; | ||
162 | + break; | ||
163 | + case GSMD_PHONEBOOK_RETRIEVE_FIND: | ||
164 | + gp = (struct gsmd_phonebook *) ((char *)gmh + sizeof(*gmh)); | ||
165 | + | ||
166 | + for (i = 0; i < nFIND; i++) { | ||
167 | + printf("%d,%s,%d,%s\n", gp->index, gp->numb, gp->type, gp->text); | ||
168 | + gp++; | ||
169 | + } | ||
170 | + | ||
171 | + nFIND = 0; | ||
172 | + break; | ||
173 | default: | ||
174 | return -EINVAL; | ||
175 | } | ||
176 | @@ -381,11 +345,13 @@ | ||
177 | "\tpd\tPB Delete (pb=index)\n" | ||
178 | "\tpr\tPB Read (pr=index)\n" | ||
179 | "\tprr\tPB Read Range (prr=index1,index2)\n" | ||
180 | - "\tpf\tPB Find (pff=indtext)\n" | ||
181 | + "\tpf\tPB Find (pf=indtext)\n" | ||
182 | "\tpw\tPB Write (pw=index,number,text)\n" | ||
183 | "\tps\tPB Support\n" | ||
184 | "\tpm\tPB Memory\n" | ||
185 | "\tpp\tPB Set Memory (pp=storage)\n" | ||
186 | + "\tpRr\tRetrieve Readrg Records\n" | ||
187 | + "\tpRf\tRetrieve Find Records\n" | ||
188 | "\tsd\tSMS Delete (sd=index,delflg)\n" | ||
189 | "\tsl\tSMS List (sl=stat)\n" | ||
190 | "\tsr\tSMS Read (sr=index)\n" | ||
191 | @@ -509,48 +475,21 @@ | ||
192 | printf("Delete Phonebook Entry\n"); | ||
193 | ptr = strchr(buf, '='); | ||
194 | lgsm_pb_del_entry(lgsmh, atoi(ptr+1)); | ||
195 | -#if 0 | ||
196 | } else if ( !strncmp(buf, "prr", 3)) { | ||
197 | printf("Read Phonebook Entries\n"); | ||
198 | struct lgsm_phonebook_readrg pb_readrg; | ||
199 | - struct gsmd_phonebook *gp_cur, *gp_cur2; | ||
200 | - | ||
201 | - /* Remove records */ | ||
202 | - if (!llist_empty(&phonebook_list)) { | ||
203 | - llist_for_each_entry_safe(gp_cur, | ||
204 | - gp_cur2, | ||
205 | - &phonebook_list, | ||
206 | - list) { | ||
207 | - llist_del(&gp_cur->list); | ||
208 | - talloc_free(gp_cur); | ||
209 | - } | ||
210 | - } | ||
211 | |||
212 | ptr = strchr(buf, '='); | ||
213 | pb_readrg.index1 = atoi(ptr+1); | ||
214 | ptr = strchr(buf, ','); | ||
215 | pb_readrg.index2 = atoi(ptr+1); | ||
216 | lgsm_pb_read_entries(lgsmh, &pb_readrg); | ||
217 | -#endif | ||
218 | } else if ( !strncmp(buf, "pr", 2)) { | ||
219 | ptr = strchr(buf, '='); | ||
220 | lgsm_pb_read_entry(lgsmh, atoi(ptr+1)); | ||
221 | -#if 0 | ||
222 | } else if ( !strncmp(buf, "pf", 2)) { | ||
223 | printf("Find Phonebook Entry\n"); | ||
224 | struct lgsm_phonebook_find pb_find; | ||
225 | - struct gsmd_phonebook *gp_cur, *gp_cur2; | ||
226 | - | ||
227 | - /* Remove records */ | ||
228 | - if (!llist_empty(&phonebook_list)) { | ||
229 | - llist_for_each_entry_safe(gp_cur, | ||
230 | - gp_cur2, | ||
231 | - &phonebook_list, | ||
232 | - list) { | ||
233 | - llist_del(&gp_cur->list); | ||
234 | - talloc_free(gp_cur); | ||
235 | - } | ||
236 | - } | ||
237 | |||
238 | ptr = strchr(buf, '='); | ||
239 | strncpy(pb_find.findtext, | ||
240 | @@ -559,7 +498,6 @@ | ||
241 | pb_find.findtext[strlen(ptr+1)] = '\0'; | ||
242 | |||
243 | lgsm_pb_find_entry(lgsmh, &pb_find); | ||
244 | -#endif | ||
245 | } else if ( !strncmp(buf, "pw", 2)) { | ||
246 | printf("Write Phonebook Entry\n"); | ||
247 | struct lgsm_phonebook pb; | ||
248 | @@ -591,6 +529,16 @@ | ||
249 | } else if ( !strncmp(buf, "ps", 2)) { | ||
250 | printf("Get Phonebook Support\n"); | ||
251 | lgsm_pb_get_support(lgsmh); | ||
252 | + } else if( !strncmp(buf, "pRr", 3) ) { | ||
253 | + printf("Retrieve Readrg Records\n"); | ||
254 | + | ||
255 | + if ( nREADRG ) | ||
256 | + lgsm_pb_retrieve_readrg(lgsmh, nREADRG); | ||
257 | + } else if( !strncmp(buf, "pRf", 3) ) { | ||
258 | + printf("Retrieve Find Records\n"); | ||
259 | + | ||
260 | + if ( nFIND ) | ||
261 | + lgsm_pb_retrieve_find(lgsmh, nFIND); | ||
262 | } else if ( !strncmp(buf, "sd", 2)) { | ||
263 | printf("Delete SMS\n"); | ||
264 | struct lgsm_sms_delete sms_del; | ||
diff --git a/meta/packages/libgsmd/files/default b/meta/packages/libgsmd/files/default new file mode 100644 index 0000000000..761100f702 --- /dev/null +++ b/meta/packages/libgsmd/files/default | |||
@@ -0,0 +1,48 @@ | |||
1 | # gsmd This shell script configures for the gsmd init script. | ||
2 | |||
3 | . /etc/init.d/functions | ||
4 | |||
5 | case `cpuinfo_id` in | ||
6 | "GTA01"|"GTA02") | ||
7 | GSMD_OPTS="-s 115200 -F" | ||
8 | GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" | ||
9 | GSM_RES="/sys/bus/platform/devices/gta01-pm-gsm.0/reset" | ||
10 | GSM_DEV="/dev/ttySAC0" | ||
11 | ;; | ||
12 | "HTC Apache"|"HTC Blueangel"|"HTC Universal") | ||
13 | GSMD_OPTS="-s 115200 -F" | ||
14 | GSM_DEV="/dev/ttyS0" | ||
15 | ;; | ||
16 | "HTC Himalaya") | ||
17 | GSMD_OPTS="-s 115200 -F" | ||
18 | GSM_DEV="/dev/ttyS2" | ||
19 | ;; | ||
20 | "HTC Magician") | ||
21 | GSMD_OPTS="-s 115200 -F" | ||
22 | GSM_DEV="/dev/ttyS1" | ||
23 | ;; | ||
24 | "Palm Treo 650") | ||
25 | GSMD_OPTS="-s 460800 -F -w 1" | ||
26 | GSM_DEV="/dev/ttyS0" | ||
27 | ;; | ||
28 | "Motorola Ezx Platform") | ||
29 | GSMD_OPTS="-s 115200 -F -v ti" | ||
30 | GSM_DEV="/dev/mux0" | ||
31 | ;; | ||
32 | *) | ||
33 | # Unknown board | ||
34 | |||
35 | # If you must specify special options, uncomment and modify the next line | ||
36 | #GSMD_OPTS="-s 115200 -F" | ||
37 | |||
38 | # If your GSM device needs to be powered up, uncomment and modify the next line | ||
39 | #GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" | ||
40 | |||
41 | # If your GSM device then needs to be reset, uncomment and modify the next line | ||
42 | #GSM_RES="/sys/bus/platform/devices/gta01-pm-gsm.0/reset" | ||
43 | |||
44 | # This should be in a common /etc/default/serial, together with | ||
45 | # BT_DEV and IR_DEV for devices that have those on a serial port | ||
46 | #GSM_DEV="/dev/ttyS1" | ||
47 | ;; | ||
48 | esac | ||
diff --git a/meta/packages/libgsmd/files/fic-gta01/gsmd b/meta/packages/libgsmd/files/fic-gta01/gsmd new file mode 100644 index 0000000000..d8323e202c --- /dev/null +++ b/meta/packages/libgsmd/files/fic-gta01/gsmd | |||
@@ -0,0 +1,49 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # gsmd This shell script starts and stops gsmd. | ||
4 | # | ||
5 | # chkconfig: 345 90 40 | ||
6 | # description: Gsmd manages access to a serial- or USB-connected GSM | ||
7 | # processname: gsmd | ||
8 | |||
9 | PATH=/bin:/usr/bin:/sbin:/usr/sbin | ||
10 | |||
11 | [ -f /etc/default/rcS ] && . /etc/default/rcS | ||
12 | [ -f /etc/default/gsmd ] && . /etc/default/gsmd | ||
13 | |||
14 | case "$1" in | ||
15 | start) | ||
16 | stty -F "$GSM_DEV" -crtscts | ||
17 | [ -n "$GSM_POW" ] && ( echo "0" >$GSM_POW; sleep 1 ) | ||
18 | stty -F "$GSM_DEV" -echo | ||
19 | [ -n "$GSM_POW" ] && ( echo "1" >$GSM_POW; sleep 1 ) | ||
20 | [ -n "$GSM_RES" ] && ( echo "1" >$GSM_RES; sleep 1 ) | ||
21 | [ -n "$GSM_RES" ] && ( echo "0" >$GSM_RES; sleep 2 ) | ||
22 | |||
23 | echo -n "Starting GSM daemon: " | ||
24 | start-stop-daemon -S -x /usr/sbin/gsmd -- gsmd -p $GSM_DEV $GSMD_OPTS >/tmp/gsm.log 2>&1 & | ||
25 | |||
26 | if [ $? = 0 ]; then | ||
27 | echo "gsmd." | ||
28 | else | ||
29 | echo "(failed.)" | ||
30 | fi | ||
31 | ;; | ||
32 | stop) | ||
33 | echo -n "Stopping GSM daemon: " | ||
34 | start-stop-daemon -K -x /usr/sbin/gsmd | ||
35 | stty -F "$GSM_DEV" -crtscts | ||
36 | [ -n "$GSM_POW" ] && echo "0" >$GSM_POW | ||
37 | echo "gsmd." | ||
38 | ;; | ||
39 | restart|force-reload) | ||
40 | $0 stop | ||
41 | $0 start | ||
42 | ;; | ||
43 | *) | ||
44 | echo "Usage: /etc/init.d/gsmd {start|stop|restart|force-reload}" | ||
45 | exit 1 | ||
46 | ;; | ||
47 | esac | ||
48 | |||
49 | exit 0 | ||
diff --git a/meta/packages/libgsmd/files/gsmd b/meta/packages/libgsmd/files/gsmd new file mode 100644 index 0000000000..9257b901ad --- /dev/null +++ b/meta/packages/libgsmd/files/gsmd | |||
@@ -0,0 +1,47 @@ | |||
1 | #! /bin/sh | ||
2 | # | ||
3 | # gsmd This shell script starts and stops gsmd. | ||
4 | # | ||
5 | # chkconfig: 345 90 40 | ||
6 | # description: Gsmd manages access to a serial- or USB-connected GSM | ||
7 | # processname: gsmd | ||
8 | |||
9 | PATH=/bin:/usr/bin:/sbin:/usr/sbin | ||
10 | |||
11 | [ -f /etc/default/rcS ] && . /etc/default/rcS | ||
12 | [ -f /etc/default/gsmd ] && . /etc/default/gsmd | ||
13 | |||
14 | case "$1" in | ||
15 | start) | ||
16 | [ -n "$GSM_POW" ] && ( echo "0" >$GSM_POW; sleep 1 ) | ||
17 | [ -n "$GSM_POW" ] && ( echo "1" >$GSM_POW; sleep 1 ) | ||
18 | [ -n "$GSM_RES" ] && ( echo "1" >$GSM_RES; sleep 1 ) | ||
19 | [ -n "$GSM_RES" ] && ( echo "0" >$GSM_RES; sleep 2 ) | ||
20 | |||
21 | echo -n "Starting GSM daemon: " | ||
22 | start-stop-daemon -S -x /usr/sbin/gsmd -- gsmd -p $GSM_DEV $GSMD_OPTS >/tmp/gsm.log 2>&1 & | ||
23 | |||
24 | if [ $? = 0 ]; then | ||
25 | echo "gsmd." | ||
26 | else | ||
27 | echo "(failed.)" | ||
28 | fi | ||
29 | ;; | ||
30 | stop) | ||
31 | [ -n "$GSM_POW" ] && echo "0" >$GSM_POW | ||
32 | |||
33 | echo -n "Stopping GSM daemon: " | ||
34 | start-stop-daemon -K -x /usr/sbin/gsmd | ||
35 | echo "gsmd." | ||
36 | ;; | ||
37 | restart|force-reload) | ||
38 | $0 stop | ||
39 | $0 start | ||
40 | ;; | ||
41 | *) | ||
42 | echo "Usage: /etc/init.d/gsmd {start|stop|restart|force-reload}" | ||
43 | exit 1 | ||
44 | ;; | ||
45 | esac | ||
46 | |||
47 | exit 0 | ||
diff --git a/meta/packages/libgsmd/files/install-ts-headers.patch b/meta/packages/libgsmd/files/install-ts-headers.patch new file mode 100644 index 0000000000..88e3b6dd1f --- /dev/null +++ b/meta/packages/libgsmd/files/install-ts-headers.patch | |||
@@ -0,0 +1,11 @@ | |||
1 | Index: gsm/include/gsmd/Makefile.am | ||
2 | =================================================================== | ||
3 | --- gsm.orig/include/gsmd/Makefile.am 2007-10-29 21:05:57.000000000 +0100 | ||
4 | +++ gsm/include/gsmd/Makefile.am 2007-10-29 21:06:03.000000000 +0100 | ||
5 | @@ -1,4 +1,4 @@ | ||
6 | |||
7 | -pkginclude_HEADERS = event.h usock.h | ||
8 | +pkginclude_HEADERS = event.h ts0705.h ts0707.h usock.h | ||
9 | |||
10 | -noinst_HEADERS = atcmd.h gsmd.h select.h ts0705.h ts0707.h unsolicited.h usock.h vendorplugin.h | ||
11 | +noinst_HEADERS = atcmd.h gsmd.h select.h unsolicited.h usock.h vendorplugin.h | ||
diff --git a/meta/packages/libgsmd/files/lgsm_send_fix_return_value.patch b/meta/packages/libgsmd/files/lgsm_send_fix_return_value.patch new file mode 100644 index 0000000000..00ba3a4549 --- /dev/null +++ b/meta/packages/libgsmd/files/lgsm_send_fix_return_value.patch | |||
@@ -0,0 +1,11 @@ | |||
1 | --- gsm/src/libgsmd/libgsmd.c.orig 2007-09-25 00:41:56.000000000 -0500 | ||
2 | +++ gsm/src/libgsmd/libgsmd.c 2007-09-25 00:43:44.000000000 -0500 | ||
3 | @@ -210,7 +210,7 @@ | ||
4 | pos += rc; | ||
5 | } | ||
6 | } | ||
7 | - return 0; | ||
8 | + return (sizeof(*gmh) + gmh->len); | ||
9 | } | ||
10 | |||
11 | struct gsmd_msg_hdr *lgsm_gmh_fill(int type, int subtype, int payload_len) | ||
diff --git a/meta/packages/libgsmd/gsmd.inc b/meta/packages/libgsmd/gsmd.inc new file mode 100644 index 0000000000..4fe36b9616 --- /dev/null +++ b/meta/packages/libgsmd/gsmd.inc | |||
@@ -0,0 +1,87 @@ | |||
1 | DESCRIPTION = "GSM libraries and daemons implementing the 07.10 specification" | ||
2 | HOMEPAGE = "http://www.openmoko.org" | ||
3 | LICENSE = "GPL LGPL" | ||
4 | SECTION = "libs/gsm" | ||
5 | PROVIDES += "gsmd" | ||
6 | RPROVIDES_${PN} = "libgsmd0 libgsmd gsmd gsmd-devel" | ||
7 | PV = "0.1+svnr${SRCREV}" | ||
8 | PR = "r37" | ||
9 | |||
10 | SRC_URI = "svn://svn.openmoko.org/trunk/src/target;module=gsm;proto=http \ | ||
11 | file://gsmd \ | ||
12 | file://default" | ||
13 | S = "${WORKDIR}/gsm" | ||
14 | |||
15 | inherit autotools pkgconfig update-rc.d | ||
16 | # handle update-rc.d RDEPENDS manually, we don't need it on | ||
17 | # anything but gsmd | ||
18 | RDEPENDS_append = "" | ||
19 | |||
20 | INITSCRIPT_NAME = "gsmd" | ||
21 | INITSCRIPT_PARAMS = "defaults 35" | ||
22 | |||
23 | do_stage() { | ||
24 | autotools_stage_all | ||
25 | } | ||
26 | |||
27 | do_install_append() { | ||
28 | install -d ${D}/${sysconfdir}/init.d | ||
29 | install -m 0755 ${WORKDIR}/gsmd ${D}/${sysconfdir}/init.d/ | ||
30 | install -d ${D}/${sysconfdir}/default | ||
31 | install ${WORKDIR}/default ${D}/${sysconfdir}/default/gsmd | ||
32 | } | ||
33 | |||
34 | PACKAGES =+ "${PN}-tools \ | ||
35 | ${BASEPN}-plugins \ | ||
36 | ${BASEPN}-plugin-machine-generic \ | ||
37 | ${BASEPN}-plugin-machine-tihtc \ | ||
38 | ${BASEPN}-plugin-vendor-bcm \ | ||
39 | ${BASEPN}-plugin-vendor-qc \ | ||
40 | ${BASEPN}-plugin-vendor-ti \ | ||
41 | ${BASEPN}-plugin-vendor-tihtc \ | ||
42 | " | ||
43 | |||
44 | RDEPENDS_${BASEPN}-plugins = "${BASEPN}-plugin-machine-generic \ | ||
45 | ${BASEPN}-plugin-machine-tihtc \ | ||
46 | ${BASEPN}-plugin-vendor-bcm \ | ||
47 | ${BASEPN}-plugin-vendor-qc \ | ||
48 | ${BASEPN}-plugin-vendor-ti \ | ||
49 | ${BASEPN}-plugin-vendor-tihtc \ | ||
50 | " | ||
51 | |||
52 | RDEPENDS_${PN} += "update-rc.d initscripts" | ||
53 | RRECOMMENDS_${PN} += "${BASEPN}-plugins" | ||
54 | |||
55 | FILES_${PN}-dbg += "${libdir}/gsmd/.debug/*" | ||
56 | FILES_${PN}-tools = "${bindir}/*" | ||
57 | FILES_${BASEPN}-plugins = "" | ||
58 | FILES_${BASEPN}-plugin-machine-generic = "${libdir}/gsmd/libgsmd-machine_generic.so*" | ||
59 | FILES_${BASEPN}-plugin-machine-tihtc = "${libdir}/gsmd/libgsmd-machine_tihtc.so*" | ||
60 | FILES_${BASEPN}-plugin-vendor-qc = "${libdir}/gsmd/libgsmd-vendor_qc.so*" | ||
61 | FILES_${BASEPN}-plugin-vendor-bcm = "${libdir}/gsmd/libgsmd-vendor_bcm.so*" | ||
62 | FILES_${BASEPN}-plugin-vendor-ti = "${libdir}/gsmd/libgsmd-vendor_ti.so*" | ||
63 | FILES_${BASEPN}-plugin-vendor-tihtc = "${libdir}/gsmd/libgsmd-vendor_tihtc.so*" | ||
64 | |||
65 | PACKAGES_DYNAMIC = "lib${BASEPN}* ${BASEPN}" | ||
66 | |||
67 | ALLOW_EMPTY_${BASEPN}-plugins = "1" | ||
68 | |||
69 | RCONFLICTS_lib${BASEPN} = "lib${CONFLICTNAME}" | ||
70 | RCONFLICTS_${BASEPN} = "${CONFLICTNAME}" | ||
71 | RCONFLICTS_${BASEPN}-plugins = "${CONFLICTNAME}-plugins" | ||
72 | RCONFLICTS_${BASEPN}-plugin-machine-generic = "${CONFLICTNAME}-plugin-machine-generic" | ||
73 | RCONFLICTS_${BASEPN}-plugin-machine-tihtc = "${CONFLICTNAME}-plugin-machine-tihtc" | ||
74 | RCONFLICTS_${BASEPN}-plugin-vendor-qc = "${CONFLICTNAME}-plugin-vendor-qc" | ||
75 | RCONFLICTS_${BASEPN}-plugin-vendor-bcm = "${CONFLICTNAME}-plugin-vendor-bcm" | ||
76 | RCONFLICTS_${BASEPN}-plugin-vendor-ti = "${CONFLICTNAME}-plugin-vendor-ti" | ||
77 | RCONFLICTS_${BASEPN}-plugin-vendor-tihtc = "${CONFLICTNAME}-plugin-vendor-tihtc" | ||
78 | |||
79 | RPROVIDES_lib${BASEPN} += "lib${CONFLICTNAME}" | ||
80 | RPROVIDES_${BASEPN} = "${CONFLICTNAME}" | ||
81 | RPROVIDES_${BASEPN}-plugins = "${CONFLICTNAME}-plugins" | ||
82 | RPROVIDES_${BASEPN}-plugin-machine-generic = "${CONFLICTNAME}-plugin-machine-generic" | ||
83 | RPROVIDES_${BASEPN}-plugin-machine-tihtc = "${CONFLICTNAME}-plugin-machine-tihtc" | ||
84 | RPROVIDES_${BASEPN}-plugin-vendor-qc = "${CONFLICTNAME}-plugin-vendor-qc" | ||
85 | RPROVIDES_${BASEPN}-plugin-vendor-bcm = "${CONFLICTNAME}-plugin-vendor-bcm" | ||
86 | RPROVIDES_${BASEPN}-plugin-vendor-ti = "${CONFLICTNAME}-plugin-vendor-ti" | ||
87 | RPROVIDES_${BASEPN}-plugin-vendor-tihtc = "${CONFLICTNAME}-plugin-vendor-tihtc" | ||
diff --git a/meta/packages/libgsmd/libgsmd/default b/meta/packages/libgsmd/libgsmd/default deleted file mode 100644 index 161c97f5fb..0000000000 --- a/meta/packages/libgsmd/libgsmd/default +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # gsmd This shell script configures for the gsmd init script. | ||
2 | |||
3 | # If you must specify special options, uncomment and modify the next line | ||
4 | #GSMD_OPTS="-s 115200 -F" | ||
5 | |||
6 | # If your GSM device needs to be powered up, uncomment and modify the next line | ||
7 | #GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" | ||
8 | |||
9 | #GSM_DEV="/dev/ttyS1" | ||
diff --git a/meta/packages/libgsmd/libgsmd/fic-gta01/default b/meta/packages/libgsmd/libgsmd/fic-gta01/default deleted file mode 100644 index 1511376a6c..0000000000 --- a/meta/packages/libgsmd/libgsmd/fic-gta01/default +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # gsmd This shell script configures for the gsmd init script. | ||
2 | |||
3 | # If you must specify special options, uncomment and modify the next line | ||
4 | GSMD_OPTS="-s 115200 -F" | ||
5 | |||
6 | # If your GSM device needs to be powered up, uncomment and modify the next line | ||
7 | GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" | ||
8 | |||
9 | GSM_DEV="/dev/ttySAC0" | ||
diff --git a/meta/packages/libgsmd/libgsmd/getopt-wait-interpreter-ready.patch b/meta/packages/libgsmd/libgsmd/getopt-wait-interpreter-ready.patch deleted file mode 100644 index 52b0da1183..0000000000 --- a/meta/packages/libgsmd/libgsmd/getopt-wait-interpreter-ready.patch +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | Index: gsm/src/gsmd/gsmd.c | ||
2 | =================================================================== | ||
3 | --- gsm.orig/src/gsmd/gsmd.c 2007-06-03 11:57:43.000000000 +0200 | ||
4 | +++ gsm/src/gsmd/gsmd.c 2007-06-03 11:57:45.000000000 +0200 | ||
5 | @@ -311,6 +311,7 @@ | ||
6 | { "leak-report", 0, NULL, 'L' }, | ||
7 | { "vendor", 1, NULL, 'v' }, | ||
8 | { "machine", 1, NULL, 'm' }, | ||
9 | + { "wait", 1, NULL, 'w' }, | ||
10 | { 0, 0, 0, 0 } | ||
11 | }; | ||
12 | |||
13 | @@ -333,6 +334,7 @@ | ||
14 | "\t-l file\t--logfile file\tSpecify a logfile to log to\n" | ||
15 | "\t-v\t--vendor v\tSpecify GSM modem vendor plugin\n" | ||
16 | "\t-m\t--machine m\tSpecify GSM modem machine plugin\n" | ||
17 | + "\t-w\t--wait m\tWait for the AT Interpreter Ready message\n" | ||
18 | ); | ||
19 | } | ||
20 | |||
21 | @@ -362,6 +364,7 @@ | ||
22 | char *logfile = "syslog"; | ||
23 | char *vendor_name = NULL; | ||
24 | char *machine_name = NULL; | ||
25 | + int wait = -1; | ||
26 | |||
27 | signal(SIGTERM, sig_handler); | ||
28 | signal(SIGINT, sig_handler); | ||
29 | @@ -374,7 +377,7 @@ | ||
30 | print_header(); | ||
31 | |||
32 | /*FIXME: parse commandline, set daemonize, device, ... */ | ||
33 | - while ((argch = getopt_long(argc, argv, "FVLdhp:s:l:v:m:", opts, NULL)) != -1) { | ||
34 | + while ((argch = getopt_long(argc, argv, "FVLdhp:s:l:v:m:w:", opts, NULL)) != -1) { | ||
35 | switch (argch) { | ||
36 | case 'V': | ||
37 | /* FIXME */ | ||
38 | @@ -411,6 +414,9 @@ | ||
39 | case 'm': | ||
40 | machine_name = optarg; | ||
41 | break; | ||
42 | + case 'w': | ||
43 | + wait = atoi(optarg); | ||
44 | + break; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | @@ -455,6 +461,9 @@ | ||
49 | exit(1); | ||
50 | } | ||
51 | |||
52 | + if (wait >= 0) | ||
53 | + g.interpreter_ready = !wait; | ||
54 | + | ||
55 | if (atcmd_init(&g, fd) < 0) { | ||
56 | fprintf(stderr, "can't initialize UART device\n"); | ||
57 | exit(1); | ||
diff --git a/meta/packages/libgsmd/libgsmd/gsmd b/meta/packages/libgsmd/libgsmd/gsmd deleted file mode 100644 index 5c78e8178a..0000000000 --- a/meta/packages/libgsmd/libgsmd/gsmd +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # gsmd This shell script starts and stops gsmd. | ||
4 | # | ||
5 | # chkconfig: 345 90 40 | ||
6 | # description: Gsmd manages access to a serial- or USB-connected GSM | ||
7 | # processname: gsmd | ||
8 | |||
9 | # Source configuration | ||
10 | . /etc/default/gsmd | ||
11 | |||
12 | # Source function library. | ||
13 | #. /etc/rc.d/init.d/functions | ||
14 | |||
15 | RETVAL=0 | ||
16 | prog="gsmd" | ||
17 | |||
18 | start() { | ||
19 | # Hack for broken uboot and/or kernel on the neo1973 | ||
20 | dmesg -n1 | ||
21 | |||
22 | if [ -n "${GSM_POW}" ] | ||
23 | then | ||
24 | if [ -e "${GSM_POW}" ] | ||
25 | then | ||
26 | echo -n "Powering up GSM device..." | ||
27 | echo "1" > ${GSM_POW} | ||
28 | sleep 1 | ||
29 | echo "done" | ||
30 | else | ||
31 | echo "GSM device not found. Aborting startup" | ||
32 | return false | ||
33 | fi | ||
34 | fi | ||
35 | # Start daemons. | ||
36 | echo -n "Starting $prog: " | ||
37 | # We don't use the daemon function here because of a known bug | ||
38 | # in initlog -- it spuriously returns a nonzero status when | ||
39 | # starting daemons that fork themselves. See | ||
40 | # http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=130629 | ||
41 | # for discussion. Fortunately: | ||
42 | # | ||
43 | # 1. gsmd startup can't fail, or at least not in the absence of | ||
44 | # much larger resource-exhaustion problems that would be very obvious. | ||
45 | # | ||
46 | # 2. We don't need all the logging crud that daemon/initlog sets | ||
47 | # up -- gsmd does its own syslog calls. | ||
48 | # | ||
49 | if [ -e "${GSM_DEV}" ] | ||
50 | then | ||
51 | gsmd -p ${GSM_DEV} ${GSMD_OPTS} >/tmp/gsm.log 2>&1 & | ||
52 | echo "success" | ||
53 | else | ||
54 | # User needs to symlink ${GPS_DEV} to the right thing | ||
55 | echo "No ${GSM_DEV} device, aborting gsmd startup." | ||
56 | fi | ||
57 | RETVAL=$? | ||
58 | echo | ||
59 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/gsmd | ||
60 | return $RETVAL | ||
61 | } | ||
62 | |||
63 | stop() { | ||
64 | # Stop daemons. | ||
65 | echo -n "Shutting down $prog: " | ||
66 | killall gsmd | ||
67 | # killproc gsmd | ||
68 | RETVAL=$? | ||
69 | echo | ||
70 | if [ $RETVAL -eq 0 ] | ||
71 | then | ||
72 | rm -f /var/lock/subsys/gsmd; | ||
73 | fi | ||
74 | return $RETVAL | ||
75 | } | ||
76 | |||
77 | # See how we were called. | ||
78 | case "$1" in | ||
79 | start) | ||
80 | start | ||
81 | ;; | ||
82 | stop) | ||
83 | stop | ||
84 | ;; | ||
85 | restart|reload) | ||
86 | stop | ||
87 | start | ||
88 | RETVAL=$? | ||
89 | ;; | ||
90 | condrestart) | ||
91 | if [ -f /var/lock/subsys/gsmd ]; then | ||
92 | stop | ||
93 | start | ||
94 | RETVAL=$? | ||
95 | fi | ||
96 | ;; | ||
97 | status) | ||
98 | # status gsmd | ||
99 | # RETVAL=$? | ||
100 | ;; | ||
101 | *) | ||
102 | echo "Usage: $0 {start|stop|restart|condrestart|status}" | ||
103 | exit 1 | ||
104 | esac | ||
105 | |||
106 | exit $RETVAL | ||
diff --git a/meta/packages/libgsmd/libgsmd/htcuniversal/default b/meta/packages/libgsmd/libgsmd/htcuniversal/default deleted file mode 100644 index b09d433d1e..0000000000 --- a/meta/packages/libgsmd/libgsmd/htcuniversal/default +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # gsmd This shell script configures for the gsmd init script. | ||
2 | |||
3 | GSMD_OPTS="-s 115200 -F -w 1" | ||
4 | |||
5 | # If your GSM device needs to be powered up, uncomment and modify the next line | ||
6 | #GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" | ||
7 | |||
8 | # this should be in a common /etc/default/serial, together | ||
9 | # with BT_DEV, and IR_DEV | ||
10 | GSM_DEV="/dev/ttyS0" | ||
diff --git a/meta/packages/libgsmd/libgsmd/magician/default b/meta/packages/libgsmd/libgsmd/magician/default deleted file mode 100644 index 523d0b9479..0000000000 --- a/meta/packages/libgsmd/libgsmd/magician/default +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # gsmd This shell script configures for the gsmd init script. | ||
2 | |||
3 | GSMD_OPTS="-s 115200 -F" | ||
4 | |||
5 | # If your GSM device needs to be powered up, uncomment and modify the next line | ||
6 | #GSM_POW="/sys/bus/platform/devices/gta01-pm-gsm.0/power_on" | ||
7 | |||
8 | # this should be in a common /etc/default/serial, together | ||
9 | # with BT_DEV, and IR_DEV | ||
10 | GSM_DEV="/dev/ttyS1" | ||
diff --git a/meta/packages/libgsmd/libgsmd/no-version.patch b/meta/packages/libgsmd/libgsmd/no-version.patch deleted file mode 100644 index 1334b32a99..0000000000 --- a/meta/packages/libgsmd/libgsmd/no-version.patch +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | --- gsm.orig/src/gsmd/Makefil.am 2007-08-01 23:35:03.000000000 +0200 | ||
2 | +++ gsm/src/gsmd/Makefile.am 2007-08-01 23:35:15.000000000 +0200 | ||
3 | 20c20 | ||
4 | < libgsmd_machine_generic_la_LDFLAGS = -module | ||
5 | --- | ||
6 | > libgsmd_machine_generic_la_LDFLAGS = -module -avoid-version | ||
7 | 22c22 | ||
8 | < libgsmd_machine_tihtc_la_LDFLAGS = -module | ||
9 | --- | ||
10 | > libgsmd_machine_tihtc_la_LDFLAGS = -module -avoid-version | ||
11 | 25c25 | ||
12 | < libgsmd_vendor_ti_la_LDFLAGS = -module | ||
13 | --- | ||
14 | > libgsmd_vendor_ti_la_LDFLAGS = -module -avoid-version | ||
15 | 27c27 | ||
16 | < libgsmd_vendor_tihtc_la_LDFLAGS = -module | ||
17 | --- | ||
18 | > libgsmd_vendor_tihtc_la_LDFLAGS = -module -avoid-version | ||
19 | 29c29 | ||
20 | < libgsmd_vendor_qc_la_LDFLAGS = -module | ||
21 | --- | ||
22 | > libgsmd_vendor_qc_la_LDFLAGS = -module -avoid-version | ||
diff --git a/meta/packages/libgsmd/libgsmd/tihtc-csq-fix.patch b/meta/packages/libgsmd/libgsmd/tihtc-csq-fix.patch deleted file mode 100644 index 3346d85809..0000000000 --- a/meta/packages/libgsmd/libgsmd/tihtc-csq-fix.patch +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | Index: gsm/src/gsmd/vendor_tihtc.c | ||
2 | =================================================================== | ||
3 | --- gsm.orig/src/gsmd/vendor_tihtc.c 2007-06-03 16:26:39.000000000 +0200 | ||
4 | +++ gsm/src/gsmd/vendor_tihtc.c 2007-06-03 16:26:41.000000000 +0200 | ||
5 | @@ -90,6 +90,8 @@ | ||
6 | struct gsmd_evt_auxdata *aux; | ||
7 | struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_SIGNAL, | ||
8 | sizeof(*aux)); | ||
9 | + static int rssi_table[] = { 0,5,10,15,20,25,99 }; | ||
10 | + unsigned int i; | ||
11 | |||
12 | DEBUGP("entering htccsq_parse param=`%s'\n", param); | ||
13 | if (!ucmd) | ||
14 | @@ -98,9 +100,10 @@ | ||
15 | |||
16 | aux = (struct gsmd_evt_auxdata *) ucmd->buf; | ||
17 | |||
18 | - /* FIXME: contains values 1-5, should be mapped to 0-31 somehow? */ | ||
19 | - /* 2 --> 11 */ | ||
20 | - aux->u.signal.sigq.rssi = atoi(buf); | ||
21 | + i = atoi(buf); | ||
22 | + if (i > 6) | ||
23 | + i = 6; | ||
24 | + aux->u.signal.sigq.rssi = rssi_table[atoi(buf)]; | ||
25 | aux->u.signal.sigq.ber = 99; | ||
26 | |||
27 | DEBUGP("sending EVT_SIGNAL\n"); | ||
diff --git a/meta/packages/libgsmd/libgsmd/universal-wcdma.patch b/meta/packages/libgsmd/libgsmd/universal-wcdma.patch deleted file mode 100644 index 350b6aba4d..0000000000 --- a/meta/packages/libgsmd/libgsmd/universal-wcdma.patch +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | Index: gsm/src/gsmd/vendor_qc.c | ||
2 | =================================================================== | ||
3 | --- gsm.orig/src/gsmd/vendor_qc.c 2007-08-01 23:35:03.000000000 +0200 | ||
4 | +++ gsm/src/gsmd/vendor_qc.c 2007-08-01 23:35:15.000000000 +0200 | ||
5 | @@ -69,8 +69,15 @@ | ||
6 | return -EIO; | ||
7 | } | ||
8 | |||
9 | +static int wcdma_parse(char *buf, int len, const char *param, | ||
10 | + struct gsmd *gsmd) | ||
11 | +{ | ||
12 | + return 0; | ||
13 | +} | ||
14 | + | ||
15 | static const struct gsmd_unsolicit qc_unsolicit[] = { | ||
16 | { "@HTCCSQ", &htccsq_parse }, /* Signal Quality */ | ||
17 | + { "[WCDMA]", &wcdma_parse }, /* ignore [WCDMA] messages */ | ||
18 | |||
19 | /* FIXME: parse the below and generate the respective events */ | ||
20 | |||
diff --git a/meta/packages/libgsmd/libgsmd_svn.bb b/meta/packages/libgsmd/libgsmd_svn.bb index f7a4620a5c..9d3ca19c04 100644 --- a/meta/packages/libgsmd/libgsmd_svn.bb +++ b/meta/packages/libgsmd/libgsmd_svn.bb | |||
@@ -1,40 +1,5 @@ | |||
1 | DESCRIPTION = "GSM libraries and daemons implementing the 07.10 specification" | 1 | BASEPN = "gsmd" |
2 | HOMEPAGE = "http://www.openmoko.org" | 2 | CONFLICTNAME = "gsmd-devel" |
3 | LICENSE = "GPL" | ||
4 | SECTION = "libs/gsm" | ||
5 | PROVIDES += "gsmd" | ||
6 | PV = "0.0+svn${SRCDATE}" | ||
7 | PR = "r17" | ||
8 | 3 | ||
9 | SRC_URI = "svn://svn.openmoko.org/trunk/src/target;module=gsm;proto=http \ | 4 | require gsmd.inc |
10 | file://gsmd \ | ||
11 | file://default \ | ||
12 | file://no-version.patch;patch=1" | ||
13 | 5 | ||
14 | S = "${WORKDIR}/gsm" | ||
15 | |||
16 | inherit autotools pkgconfig update-rc.d | ||
17 | |||
18 | INITSCRIPT_NAME = "gsm" | ||
19 | INITSCRIPT_PARAMS = "defaults 35" | ||
20 | |||
21 | do_stage() { | ||
22 | autotools_stage_all | ||
23 | } | ||
24 | |||
25 | do_install_append() { | ||
26 | install -d ${D}/${sysconfdir}/init.d | ||
27 | install -m 0755 ${WORKDIR}/gsmd ${D}/${sysconfdir}/init.d/gsm | ||
28 | install -d ${D}/${sysconfdir}/default | ||
29 | install ${WORKDIR}/default ${D}/${sysconfdir}/default/gsmd | ||
30 | } | ||
31 | |||
32 | PACKAGES =+ "${PN}-tools gsmd gsmd-plugins" | ||
33 | RDEPENDS_${PN} = "gsmd" | ||
34 | RRECOMMENDS_gsmd = "gsmd-plugins" | ||
35 | FILES_${PN}-tools = "${bindir}/*" | ||
36 | FILES_gsmd = "${sbindir}/gsmd ${sysconfdir}" | ||
37 | FILES_gsmd-plugins = "${libdir}/gsmd/*.so*" | ||
38 | FILES_${PN}-dbg += "${libdir}/gsmd/.debug/*.so" | ||
39 | |||
40 | PACKAGES_DYNAMIC = "libgsmd* gsmd" | ||