summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/gsm/files/027_phonebook-find-and-read-range-support.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-connectivity/gsm/files/027_phonebook-find-and-read-range-support.patch')
-rw-r--r--meta/recipes-connectivity/gsm/files/027_phonebook-find-and-read-range-support.patch423
1 files changed, 423 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/gsm/files/027_phonebook-find-and-read-range-support.patch b/meta/recipes-connectivity/gsm/files/027_phonebook-find-and-read-range-support.patch
new file mode 100644
index 0000000000..ea0f12daac
--- /dev/null
+++ b/meta/recipes-connectivity/gsm/files/027_phonebook-find-and-read-range-support.patch
@@ -0,0 +1,423 @@
1From: Sean Chiang <sean_chiang@openmoko.com>
2Subject: [PATCH] Improvement for find and read phonebooks in gsmd
3
4This patch is an improvement for find and read phonebooks.
5After clients make a request to find / read phonebooks, then clients
6should make a request to retrieve all the records.
7
8Signed-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
17Index: 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
32Index: 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 */
46Index: 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);
99Index: 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+}
162Index: 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);