Implemented GetPhonebookInfo
[gsmd2.git] / src / device.c
blob99dcaf86b32ceae077182e8f665cb0bfb4961ac9
1 /*
2 * device.c
4 * Copyright(C) 2007,2008 Ixonos Plc
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Boston, MA 02111.
22 * Written by
23 * Jukka Honkela
24 * Yi Zheng
25 * Matti Katila
26 * Vesa Pikki
27 * Heikki Paajanen
30 #include <string.h>
32 #include "device.h"
34 #include "utils.h"
35 #include "modem.h"
37 static
38 AtCommandHandlerStatus gsmd_device_handler_query_date_time (ModemInterface *modem,
39 AtCommandContext *at,
40 GString *response);
41 static
42 AtCommandHandlerStatus gsmd_device_handler_set_date_time (ModemInterface *modem,
43 AtCommandContext *at,
44 GString *response);
45 static
46 AtCommandHandlerStatus gsmd_device_handler_query_imei (ModemInterface *modem,
47 AtCommandContext *at,
48 GString *response);
49 static
50 AtCommandHandlerStatus gsmd_device_handler_query_revision (ModemInterface *modem,
51 AtCommandContext *at,
52 GString *response);
53 static
54 AtCommandHandlerStatus gsmd_device_handler_query_model (ModemInterface *modem,
55 AtCommandContext *at,
56 GString *response);
57 static
58 AtCommandHandlerStatus gsmd_device_handler_query_manufacturer (ModemInterface *modem,
59 AtCommandContext *at,
60 GString *response);
61 static
62 AtCommandHandlerStatus gsmd_device_handler_get_antenna_power (ModemInterface *modem,
63 AtCommandContext *at,
64 GString *response);
65 static
66 AtCommandHandlerStatus gsmd_device_handler_get_info (ModemInterface *modem,
67 AtCommandContext *at,
68 GString *response);
70 static const AtCommand
71 device_commands[]
72 = {
73 //Query datetime
74 { DATE_TIME_QUERY, "AT+CCLK?\r\n", 100,
75 TRUE, 0,
76 gsmd_device_handler_query_date_time, NULL, SIM_READY, NULL},
78 //Set datetime
79 { SET_DATE_TIME, "AT+CCLK=\"%s\"\r\n", 100000,
80 FALSE, 0,
81 gsmd_device_handler_set_date_time, NULL, SIM_READY, NULL},
83 //Get IMEI
84 { IMEI_QUERY, "AT+CGSN\r\n", 100,
85 FALSE, 0,
86 gsmd_device_handler_query_imei, NULL, SIM_UNKNOWN, NULL},
88 //Get SW revision
89 { SW_REVISION_QUERY, "AT+CGMR\r\n", 100,
90 FALSE, 0,
91 gsmd_device_handler_query_revision, NULL, SIM_UNKNOWN, NULL},
93 //Get model
94 { MODEL_QUERY, "AT+CGMM\r\n", 100,
95 FALSE, 0,
96 gsmd_device_handler_query_model, NULL, SIM_UNKNOWN, NULL},
98 //Get manufacturer
99 { MANUFACTURER_QUERY, "AT+CGMI\r\n", 100,
100 FALSE, 0,
101 gsmd_device_handler_query_manufacturer, NULL, SIM_UNKNOWN, NULL},
103 //Get antenna power
104 { ANTENNA_POWER_GET, "AT+CFUN?\r\n", 100,
105 FALSE, 0,
106 gsmd_device_handler_get_antenna_power, NULL, SIM_UNKNOWN, NULL},
108 /* //Get capabilities */
109 /* { CAPABILITIES_GET, "AT+GCAP\r\n", 100, */
110 /* FALSE, 0, */
111 /* gsmd_device_handler_get_features, NULL, SIM_UNKNOWN}, */
113 { 0, NULL, 100, TRUE, 1,
114 NULL, NULL, SIM_UNKNOWN },
116 }, *device_command_p = device_commands;
118 static const SymbolTable
119 device_symbols[] = {
120 { "CCLK", SYMBOL_CCLK, },
121 { "CFUN", SYMBOL_CFUN, },
122 { "CGSN", SYMBOL_CGSN, },
123 { "CGMR", SYMBOL_CGMR, },
124 { "CGMM", SYMBOL_CGMM, },
125 { "CGMI", SYMBOL_CGMI, },
126 { NULL, 0, },
127 }, *device_symbol_p = device_symbols;
130 void gsmd_device_init_at_handler(ModemInterface* modem)
132 g_debug("%s", __func__);
134 while (device_symbol_p->symbol_name) {
135 g_scanner_add_symbol (modem->scanner, device_symbol_p->symbol_name,
136 GINT_TO_POINTER(device_symbol_p->symbol_token));
137 device_symbol_p++;
139 while (device_command_p->command) {
140 gsmd_modem_register_command (modem,device_command_p);
141 device_command_p++;
146 * @brief AtCommand to query datetime
148 * @param modem modem whose response to handle
150 static void gsmd_device_command_query_date_time (DeviceInterface *device,
151 gpointer ipc_data)
153 ModemInterface *modem = (ModemInterface*)device->priv;
154 gsmd_modem_post_at_command_id( modem,
155 DATE_TIME_QUERY,
156 NULL,
157 ipc_data,
158 NULL, NULL,
159 INTERFACE_DEVICE,
160 NULL);
165 * @brief AtCommand to set datetime
167 * @param modem modem whose response to handle
168 * @param date_time datetime to set. Format "yy/MM/dd,hh:mm:ss±zz"
170 static void gsmd_device_command_set_date_time (DeviceInterface *device,
171 gpointer ipc_data,
172 const char* date_time)
174 ModemInterface *modem = (ModemInterface*)device->priv;
175 gsmd_modem_post_at_command_id( modem,
176 SET_DATE_TIME,
177 date_time,
178 ipc_data,
179 NULL, NULL,
180 INTERFACE_DEVICE,
181 NULL);
186 * @brief Handler to modems response from setDateTime command
188 * @param modem modem whose response to handle
189 * @return true if responses were recognized
191 static
192 AtCommandHandlerStatus gsmd_device_handler_set_date_time (ModemInterface *modem,
193 AtCommandContext *at, GString *response)
195 GScanner* scanner = modem->scanner;
196 // g_message ("Set datatime handler\n");
197 if (scanner->token == SYMBOL_OK) {
198 //TODO smartphone doesn't have datetime methods so they need
199 //to be specified or this code moved elsewhere
201 if (modem->modem_interface->setDateTimeResp)
202 modem->modem_interface->setDateTimeResp (modem,TRUE);
204 return AT_HANDLER_DONE;
205 } else if (scanner->token == SYMBOL_ERROR) { //if format uncorrect,
206 //TODO smartphone doesn't have datetime methods so they need to
207 //be specified or this code moved elsewhere
209 if (modem->modem_interface->setDateTimeResp)
210 modem->modem_interface->setDateTimeResp (modem,FALSE);
212 return AT_HANDLER_DONE;
214 if (scanner->token == SYMBOL_TIME_OUT) {
215 return AT_HANDLER_DONE;
217 return AT_HANDLER_DONT_UNDERSTAND;
221 * @brief Handler to modems response from queryDateTime command
223 * @param modem modem whose response to handle
224 * @return true if responses were recognized
226 static
227 AtCommandHandlerStatus gsmd_device_handler_query_date_time (ModemInterface *modem,
228 AtCommandContext *at,
229 GString *response)
231 GScanner* scanner = modem->scanner;
232 // g_message ("Query datatime handler\n");
233 //AT+CCLK=?
234 // +CCLK: "02/09/07,22:30:25"
235 if (gsmd_utils_check_end_token(scanner)) {
236 return AT_HANDLER_DONE;
238 if (scanner->token == SYMBOL_TIME_OUT) {
239 return AT_HANDLER_DONE;
241 if (scanner->token != '+')
242 return AT_HANDLER_DONT_UNDERSTAND;
243 g_scanner_get_next_token (scanner);
244 if (scanner->token == SYMBOL_CCLK) {
245 g_scanner_get_next_token (scanner);//get :
246 g_scanner_get_next_token (scanner);//get string
247 GString* date_time_str = g_string_new (scanner->value.v_string);
248 /* //TODO datetime methods arent specified in freesmartphone's api
249 if (modem->device->dateTime)
250 modem->device->dateTime (modem,date_time_str);
252 g_string_free (date_time_str, TRUE);
253 return AT_HANDLER_DONE;
255 return AT_HANDLER_DONT_UNDERSTAND;
258 static
259 AtCommandHandlerStatus gsmd_device_get_info_handler(ModemInterface* modem,
260 AtCommandContext *at,
261 gchar *key,
262 const gchar *errormsg,
263 const gchar *timeoutmsg)
265 GScanner* scanner = modem->scanner;
266 GValue *val = NULL;
268 if (scanner->token == SYMBOL_OK) {
269 val = g_hash_table_lookup(at->handler_data,key);
270 if (!val) {
271 gsmd_utils_send_error(at,GSMD_ERROR_UNKNOWN,"INVALID HANDLER DATA");
272 g_warning("%s : Invalid handler data: %p",
273 __func__,
274 val);
276 return AT_HANDLER_DONE_ERROR;
279 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],key,val);
281 return AT_HANDLER_DONE;
282 } else if (scanner->token == G_TOKEN_EOF) {
283 return AT_HANDLER_NEED_MORE;
284 } else if (gsmd_utils_send_error_from_response(at,
285 scanner,
286 errormsg,
287 timeoutmsg)) {
288 return AT_HANDLER_DONE_ERROR;
291 return AT_HANDLER_DONT_UNDERSTAND;
294 static
295 AtCommandHandlerStatus gsmd_device_handler_query_imei ( ModemInterface* modem,
296 AtCommandContext *at,
297 GString *response)
300 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
302 GSMD_DEVICE_KEY_IMEI,
303 "ERROR OCCURRED WHEN QUERYING IMEI",
304 "TIMEOUT OCCURRED WHEN QUERYING IMEI");
305 if (status != AT_HANDLER_DONT_UNDERSTAND) {
306 return status;
308 GScanner* scanner = modem->scanner;
309 gchar *res = NULL;
310 if ( scanner->token == '+' ) {
311 g_scanner_get_next_token (scanner);
312 if ( scanner->token == SYMBOL_CGSN ) {
313 g_scanner_get_next_token (scanner);
314 if (scanner->token == ':') {
315 g_scanner_peek_next_token (scanner);
316 if ( scanner->next_token == G_TOKEN_INT) {
317 res = g_strdup(response->str+g_scanner_cur_position(scanner));
318 res = g_strstrip(res);
322 } else {
323 res = g_strdup(response->str);
324 res = g_strstrip(res);
326 if ( res ) {
327 gboolean is_imei = TRUE;
328 gint i = 0;
329 if ( strlen(res) == 15 ) {
330 for (i=0; i < 15;i++) {
331 if ( !g_ascii_isdigit(res[i]) ) {
332 is_imei = FALSE;
333 break;
336 } else {
337 is_imei = FALSE;
339 if ( !is_imei ) {
340 g_debug("%s : %s is not IMEI",__func__, res);
341 g_free( res );
342 return AT_HANDLER_DONT_UNDERSTAND;
345 g_debug("%s : IMEI: %s",__func__, res);
347 gsmd_utils_table_insert_string(at->handler_data,GSMD_DEVICE_KEY_IMEI,res);
349 g_free( res );
351 return AT_HANDLER_NEED_MORE;
353 static
354 AtCommandHandlerStatus gsmd_device_handler_query_revision (ModemInterface *modem,
355 AtCommandContext *at,
356 GString *response)
358 g_debug("%s : %s",__func__, response->str);
359 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
361 GSMD_DEVICE_KEY_MODEM_REVISION,
362 "ERROR OCCURRED WHEN QUERYING REVISION",
363 "TIMEOUT OCCURRED WHEN QUERYING REVISION");
364 if (status != AT_HANDLER_DONT_UNDERSTAND)
365 return status;
368 GScanner* scanner = modem->scanner;
369 gchar *res = NULL;;
370 if ( scanner->token == '+' ) {
371 g_scanner_get_next_token (scanner);
372 if ( scanner->token == SYMBOL_CGMR ) {
373 g_scanner_get_next_token (scanner);
374 if (scanner->token == ':') {
375 g_scanner_peek_next_token (scanner);
376 if ( scanner->next_token == G_TOKEN_STRING ) {
377 g_scanner_get_next_token (scanner);
378 res = g_strdup(scanner->value.v_string);
379 } else {
380 res = g_strdup(response->str+g_scanner_cur_position(scanner));
381 res = g_strstrip(res);
383 g_debug("%s : manu: '%s'", __func__, res);
386 } else {
387 res = g_strdup(response->str);
388 res = g_strstrip(res);
390 if ( res && strlen(res) > 0 ) {
391 g_debug("%s : SW revision: %s",__func__, res);
392 gsmd_utils_table_insert_string(at->handler_data,
393 GSMD_DEVICE_KEY_MODEM_REVISION,
394 res);
397 g_free(res);
398 return AT_HANDLER_NEED_MORE;
400 static
401 AtCommandHandlerStatus gsmd_device_handler_query_manufacturer (ModemInterface *modem,
402 AtCommandContext *at,
403 GString *response)
405 g_debug("%s : %s",__func__, response->str);
406 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
408 GSMD_DEVICE_KEY_MODEM_VENDOR,
409 "ERROR OCCURRED WHEN QUERYING MANUFACTURE",
410 "TIMEOUT OCCURRED WHEN QUERYING MANUFACTURER");
411 if (status != AT_HANDLER_DONT_UNDERSTAND)
412 return status;
414 GScanner* scanner = modem->scanner;
415 gchar *res = NULL;;
416 if ( scanner->token == '+' ) {
417 g_scanner_get_next_token (scanner);
418 if ( scanner->token == SYMBOL_CGMI ) {
419 g_scanner_get_next_token (scanner);
420 if (scanner->token == ':') {
421 g_scanner_peek_next_token (scanner);
422 if ( scanner->next_token == G_TOKEN_STRING ) {
423 g_scanner_get_next_token (scanner);
424 res = g_strdup(scanner->value.v_string);
425 } else {
426 res = g_strdup(response->str+g_scanner_cur_position(scanner));
427 res = g_strstrip(res);
429 g_debug("%s : manu: '%s'", __func__, res);
432 } else {
433 res = g_strdup(response->str);
434 res = g_strstrip(res);
436 if ( res && strlen(res) > 0 ) {
437 g_debug("%s : manufacturer: %s",__func__, res);
438 gsmd_utils_table_insert_string(at->handler_data,
439 GSMD_DEVICE_KEY_MODEM_VENDOR,
440 res);
444 g_free(res);
445 return AT_HANDLER_NEED_MORE;
447 static
448 AtCommandHandlerStatus gsmd_device_handler_query_model (ModemInterface *modem,
449 AtCommandContext *at,
450 GString *response)
452 g_debug("%s : %s",__func__, response->str);
453 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
455 GSMD_DEVICE_KEY_MODEM_MODEL,
456 "ERROR OCCURRED WHEN QUERYING MODEL",
457 "TIMEOUT OCCURRED WHEN QUERYING MODEL");
458 if (status != AT_HANDLER_DONT_UNDERSTAND)
459 return status;
461 GScanner* scanner = modem->scanner;
462 gchar *res = NULL;;
463 if ( scanner->token == '+' ) {
464 g_scanner_get_next_token (scanner);
465 if ( scanner->token == SYMBOL_CGMM ) {
466 g_scanner_get_next_token (scanner);
467 if (scanner->token == ':') {
468 g_scanner_peek_next_token (scanner);
469 if ( scanner->next_token == G_TOKEN_STRING ) {
470 g_scanner_get_next_token (scanner);
471 res = g_strdup(scanner->value.v_string);
472 } else {
473 res = g_strdup(response->str+g_scanner_cur_position(scanner));
474 res = g_strstrip(res);
476 g_debug("%s : manu: '%s'", __func__, res);
479 } else {
480 res = g_strdup(response->str);
481 res = g_strstrip(res);
483 if ( res && strlen(res) > 0 ) {
484 g_debug("%s : model: %s",__func__, res);
485 gsmd_utils_table_insert_string(at->handler_data,
486 GSMD_DEVICE_KEY_MODEM_MODEL,
487 res);
489 g_free(res);
491 return AT_HANDLER_NEED_MORE;
495 static gboolean gsmd_device_command_get_info_reply(ModemInterface *modem,
496 gpointer ipc_data)
498 GValue *vendor = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_VENDOR);
499 GValue *model = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_MODEL);
500 GValue *revision = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_REVISION);
501 GValue *imei = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_IMEI);
504 if (!vendor || !model || !revision || !imei)
505 return FALSE;
508 GHashTable *table = gsmd_utils_create_hash_table();
510 gsmd_utils_table_insert_copy(table,GSMD_DEVICE_KEY_MODEM_VENDOR,vendor);
511 gsmd_utils_table_insert_copy(table,GSMD_DEVICE_KEY_MODEM_MODEL,model);
512 gsmd_utils_table_insert_copy(table,GSMD_DEVICE_KEY_MODEM_REVISION,revision);
513 gsmd_utils_table_insert_copy(table,GSMD_DEVICE_KEY_IMEI,imei);
515 modem->device_ipc->get_info_reply( modem->device_ipc,
516 ipc_data,
517 table);
518 g_hash_table_destroy(table);
519 return TRUE;
522 static
523 AtCommandHandlerStatus gsmd_device_handler_get_info (ModemInterface *modem,
524 AtCommandContext *at,
525 GString *response)
527 AtCommandHandlerStatus status = AT_HANDLER_DONT_UNDERSTAND;
528 AtCommandContext *cmd = NULL;
529 switch (at->command->cmd_id) {
530 case IMEI_QUERY:
531 g_debug("%s : IMEI_QUERY", __func__);
532 /* status = gsmd_device_handler_query_imei(modem,at,response); */
533 status = at->command->handler(modem,at,response);
534 switch (status) {
535 case AT_HANDLER_DONE_ERROR:
536 case AT_HANDLER_ERROR:
537 return AT_HANDLER_DONE_ERROR;
538 break;
539 case AT_HANDLER_DONE:
540 if ( !g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_IMEI) ) {
541 gsmd_utils_send_error(at,GSMD_ERROR_UNKNOWN,"UNABLE TO READ IMEI");
542 return AT_HANDLER_DONE_ERROR;
544 g_hash_table_remove(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_VENDOR);
546 cmd = gsmd_at_command_context_new_from_id( modem,
547 MANUFACTURER_QUERY,
548 NULL,/*param*/
549 at->ipc_data,
550 at->error_function,
551 at->error_data,
552 NULL);
553 cmd->handler = &gsmd_device_handler_get_info;
554 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
555 status = AT_HANDLER_DONE;
556 break;
557 case AT_HANDLER_DONT_UNDERSTAND:
558 case AT_HANDLER_NEED_MORE:
559 case AT_HANDLER_RETRY:
560 return status;
562 break;
563 case MANUFACTURER_QUERY:
564 g_debug("%s : MANUFACTURER_QUERY", __func__);
565 status = at->command->handler(modem,at,response);
566 switch (status) {
567 case AT_HANDLER_DONE_ERROR:
568 case AT_HANDLER_ERROR:
569 return AT_HANDLER_DONE_ERROR;
570 case AT_HANDLER_DONE:
571 if ( !g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_VENDOR) ) {
572 gsmd_utils_send_error(at,GSMD_ERROR_UNKNOWN,"UNABLE TO READ MANUFACTURER");
573 return AT_HANDLER_DONE_ERROR;
576 g_hash_table_remove(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_REVISION);
577 cmd = gsmd_at_command_context_new_from_id( modem,
578 SW_REVISION_QUERY,
579 NULL,/*param*/
580 at->ipc_data,
581 at->error_function,
582 at->error_data,
583 NULL);
584 cmd->handler = &gsmd_device_handler_get_info;
585 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
586 status = AT_HANDLER_DONE;
587 break;
588 case AT_HANDLER_DONT_UNDERSTAND:
589 case AT_HANDLER_NEED_MORE:
590 case AT_HANDLER_RETRY:
591 return status;
593 break;
594 case SW_REVISION_QUERY:
595 g_debug("%s : SW_REVISION_QUERY", __func__);
596 status = at->command->handler(modem,at,response);
597 switch (status) {
598 case AT_HANDLER_DONE_ERROR:
599 case AT_HANDLER_ERROR:
600 return AT_HANDLER_DONE_ERROR;
601 case AT_HANDLER_DONE:
602 if ( !g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_REVISION) ) {
603 gsmd_utils_send_error(at,GSMD_ERROR_UNKNOWN,"UNABLE TO READ SW REVISION");
604 return AT_HANDLER_DONE_ERROR;
607 g_hash_table_remove(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_MODEL);
608 cmd = gsmd_at_command_context_new_from_id( modem,
609 MODEL_QUERY,
610 NULL,/*param*/
611 at->ipc_data,
612 at->error_function,
613 at->error_data,
614 NULL);
615 cmd->handler = &gsmd_device_handler_get_info;
616 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
617 status = AT_HANDLER_DONE;
618 break;
619 case AT_HANDLER_DONT_UNDERSTAND:
620 case AT_HANDLER_NEED_MORE:
621 case AT_HANDLER_RETRY:
622 return status;
624 break;
625 case MODEL_QUERY:
626 g_debug("%s : MODEL_QUERY", __func__);
627 status = gsmd_device_handler_query_model(modem,at,response);
628 switch (status) {
629 case AT_HANDLER_DONE_ERROR:
630 case AT_HANDLER_ERROR:
631 return AT_HANDLER_DONE_ERROR;
632 break;
633 case AT_HANDLER_DONE:
634 gsmd_device_command_get_info_reply(modem,at->ipc_data);
636 break;
637 case AT_HANDLER_DONT_UNDERSTAND:
638 case AT_HANDLER_NEED_MORE:
639 case AT_HANDLER_RETRY:
640 return status;
642 break;
644 return status;
649 void gsmd_device_command_get_info( DeviceInterface *device, gpointer ipc_data)
651 ModemInterface *modem = (ModemInterface*)device->priv;
652 if (modem->no_cache || !gsmd_device_command_get_info_reply(modem,ipc_data)) {
653 g_hash_table_remove(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_IMEI);
654 AtCommandContext *cmd = NULL;
655 cmd = gsmd_at_command_context_new_from_id( modem,
656 IMEI_QUERY,
657 NULL,/*param*/
658 ipc_data,
659 (ErrorFunction)modem->device_ipc->get_info_error,
660 modem->device_ipc,
661 NULL);
662 cmd->handler = &gsmd_device_handler_get_info;
663 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
668 void gsmd_device_command_set_antenna_power( DeviceInterface *device,
669 gpointer ipc_data,
670 gboolean antenna_power)
672 //TODO implement
676 static
677 AtCommandHandlerStatus gsmd_device_handler_get_antenna_power (ModemInterface *modem,
678 AtCommandContext *at,
679 GString *response)
681 GScanner* scanner = modem->scanner;
682 GValue *val = NULL;
683 // g_message ("Query datatime handler\n");
684 //AT+CCLK=?
685 // +CCLK: "02/09/07,22:30:25"
686 if (scanner->token == SYMBOL_OK) {
687 val = g_hash_table_lookup(at->handler_data,GSMD_DEVICE_KEY_POWER);
690 if (!val) {
691 g_warning("%s : Invalid handler data. power: %p",
692 __func__,
693 val);
695 gsmd_utils_send_error(at,
696 GSMD_ERROR_UNKNOWN,
697 "INVALID HANDLER DATA");
701 if (!val)
702 return AT_HANDLER_DONE_ERROR;
705 modem->device_ipc->get_antenna_power_reply(modem->device_ipc,
706 at->ipc_data,
707 g_value_get_boolean(val));
709 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],
710 GSMD_DEVICE_KEY_POWER,
711 val);
712 return AT_HANDLER_DONE;
716 if (gsmd_utils_send_error_from_response(at,
717 scanner,
718 "FAILED TO GET ANTENNA POWER",
719 "TIMEOUT WHEN GETTING ANTENNA POWER")) {
720 return AT_HANDLER_DONE_ERROR;
723 if (scanner->token != '+') {
724 return AT_HANDLER_DONT_UNDERSTAND;
726 g_scanner_get_next_token (scanner);
727 if (scanner->token == SYMBOL_CFUN) {
728 g_scanner_get_next_token (scanner);//get :
729 g_scanner_get_next_token (scanner);//get string
731 gsmd_utils_table_insert_boolean(at->handler_data,
732 GSMD_DEVICE_KEY_POWER,
733 scanner->value.v_int);
734 return AT_HANDLER_NEED_MORE;
736 return AT_HANDLER_DONT_UNDERSTAND;
739 void gsmd_device_command_get_antenna_power( DeviceInterface *device,
740 gpointer ipc_data)
742 ModemInterface *modem = (ModemInterface*)device->priv;
743 if (modem->no_cache || !g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_POWER)) {
744 gsmd_modem_post_at_command_id( modem,
745 ANTENNA_POWER_GET,
746 NULL,
747 ipc_data,
748 (ErrorFunction)modem->device_ipc->get_antenna_power_error,
749 (gpointer)modem->device_ipc,
750 INTERFACE_DEVICE,
751 NULL);
752 } else {
753 GValue *val = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_POWER);
754 if (val) {
755 modem->device_ipc->get_antenna_power_reply(modem->device_ipc,
756 ipc_data,
757 g_value_get_boolean(val));
764 void gsmd_device_command_prepare_to_suspend( DeviceInterface *device,
765 gpointer ipc_data)
769 void gsmd_device_command_recover_from_suspend( DeviceInterface *device,
770 gpointer ipc_data)
774 void gsmd_device_command_get_features( DeviceInterface *device, gpointer ipc_data)
776 ModemInterface *modem = (ModemInterface*)device->priv;
777 GHashTable *table = gsmd_utils_create_hash_table();
779 modem->device_ipc->get_features_reply( modem->device_ipc,
780 ipc_data,
781 table);
782 g_hash_table_destroy(table);
786 void gsmd_device_init(ModemInterface *modem)
788 gsmd_device_init_at_handler(modem);
790 modem->device->priv = (gpointer)modem;
791 modem->device->prepare_to_suspend = &gsmd_device_command_prepare_to_suspend;
792 modem->device->recover_from_suspend = &gsmd_device_command_recover_from_suspend;
793 modem->device->get_date_time = &gsmd_device_command_query_date_time;
794 modem->device->set_date_time = &gsmd_device_command_set_date_time;
795 modem->device->get_info = &gsmd_device_command_get_info;
796 modem->device->set_antenna_power = &gsmd_device_command_set_antenna_power;
797 modem->device->get_antenna_power = &gsmd_device_command_get_antenna_power;
798 modem->device->get_features = &gsmd_device_command_get_features;