Fixed typo in error message.
[gsmd2.git] / src / device.c
blob5969e3fb42ef17041dc12caf16802d954898f5fc
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 while (device_symbol_p->symbol_name) {
133 g_scanner_add_symbol (modem->scanner, device_symbol_p->symbol_name,
134 GINT_TO_POINTER(device_symbol_p->symbol_token));
135 device_symbol_p++;
137 while (device_command_p->command) {
138 gsmd_modem_register_command (modem,device_command_p);
139 device_command_p++;
144 * @brief AtCommand to query datetime
146 * @param modem modem whose response to handle
148 static void gsmd_device_command_query_date_time (DeviceInterface *device,
149 gpointer ipc_data)
151 ModemInterface *modem = (ModemInterface*)device->priv;
152 gsmd_modem_post_at_command_id( modem,
153 DATE_TIME_QUERY,
154 NULL,
155 ipc_data,
156 NULL, NULL,
157 INTERFACE_DEVICE,
158 NULL);
163 * @brief AtCommand to set datetime
165 * @param modem modem whose response to handle
166 * @param date_time datetime to set. Format "yy/MM/dd,hh:mm:ss±zz"
168 static void gsmd_device_command_set_date_time (DeviceInterface *device,
169 gpointer ipc_data,
170 const char* date_time)
172 ModemInterface *modem = (ModemInterface*)device->priv;
173 gsmd_modem_post_at_command_id( modem,
174 SET_DATE_TIME,
175 date_time,
176 ipc_data,
177 NULL, NULL,
178 INTERFACE_DEVICE,
179 NULL);
184 * @brief Handler to modems response from setDateTime command
186 * @param modem modem whose response to handle
187 * @return true if responses were recognized
189 static
190 AtCommandHandlerStatus gsmd_device_handler_set_date_time (ModemInterface *modem,
191 AtCommandContext *at, GString *response)
193 GScanner* scanner = modem->scanner;
194 // g_message ("Set datatime handler\n");
195 if (scanner->token == SYMBOL_OK) {
196 //TODO smartphone doesn't have datetime methods so they need
197 //to be specified or this code moved elsewhere
199 if (modem->modem_interface->setDateTimeResp)
200 modem->modem_interface->setDateTimeResp (modem,TRUE);
202 return AT_HANDLER_DONE;
203 } else if (scanner->token == SYMBOL_ERROR) { //if format uncorrect,
204 //TODO smartphone doesn't have datetime methods so they need to
205 //be specified or this code moved elsewhere
207 if (modem->modem_interface->setDateTimeResp)
208 modem->modem_interface->setDateTimeResp (modem,FALSE);
210 return AT_HANDLER_DONE;
212 if (scanner->token == SYMBOL_TIME_OUT) {
213 return AT_HANDLER_DONE;
215 return AT_HANDLER_DONT_UNDERSTAND;
219 * @brief Handler to modems response from queryDateTime command
221 * @param modem modem whose response to handle
222 * @return true if responses were recognized
224 static
225 AtCommandHandlerStatus gsmd_device_handler_query_date_time (ModemInterface *modem,
226 AtCommandContext *at,
227 GString *response)
229 GScanner* scanner = modem->scanner;
230 // g_message ("Query datatime handler\n");
231 //AT+CCLK=?
232 // +CCLK: "02/09/07,22:30:25"
233 if (gsmd_utils_check_end_token(scanner)) {
234 return AT_HANDLER_DONE;
236 if (scanner->token == SYMBOL_TIME_OUT) {
237 return AT_HANDLER_DONE;
239 if (scanner->token != '+')
240 return AT_HANDLER_DONT_UNDERSTAND;
241 g_scanner_get_next_token (scanner);
242 if (scanner->token == SYMBOL_CCLK) {
243 g_scanner_get_next_token (scanner);//get :
244 g_scanner_get_next_token (scanner);//get string
245 GString* date_time_str = g_string_new (scanner->value.v_string);
246 /* //TODO datetime methods arent specified in freesmartphone's api
247 if (modem->device->dateTime)
248 modem->device->dateTime (modem,date_time_str);
250 g_string_free (date_time_str, TRUE);
251 return AT_HANDLER_DONE;
253 return AT_HANDLER_DONT_UNDERSTAND;
256 static
257 AtCommandHandlerStatus gsmd_device_get_info_handler(ModemInterface* modem,
258 AtCommandContext *at,
259 GString *response,
260 gchar *key,
261 const gchar *errormsg,
262 const gchar *timeoutmsg)
264 GScanner* scanner = modem->scanner;
265 GValue *val = NULL;
267 if (scanner->token == SYMBOL_OK) {
268 val = g_hash_table_lookup(at->handler_data,key);
269 if (!val) {
270 gsmd_utils_send_error(at,GSMD_ERROR_UNKNOWN,"OK WITHOUT RESPONSE");
271 g_warning("%s : Invalid handler data: %p",
272 __func__,
273 val);
275 return AT_HANDLER_DONE_ERROR;
278 return AT_HANDLER_DONE;
279 } else if (scanner->token == G_TOKEN_EOF) {
280 return AT_HANDLER_NEED_MORE;
281 } else if (gsmd_utils_send_error_from_response(at,
282 response,
283 errormsg,
284 timeoutmsg)) {
285 return AT_HANDLER_DONE_ERROR;
288 return AT_HANDLER_DONT_UNDERSTAND;
291 static
292 AtCommandHandlerStatus gsmd_device_handler_query_imei ( ModemInterface* modem,
293 AtCommandContext *at,
294 GString *response)
297 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
299 response,
300 GSMD_DEVICE_KEY_IMEI,
301 "ERROR OCCURRED WHEN QUERYING IMEI",
302 "TIMEOUT OCCURRED WHEN QUERYING IMEI");
303 if (status != AT_HANDLER_DONT_UNDERSTAND) {
304 return status;
306 GScanner* scanner = modem->scanner;
307 gchar *res = NULL;
308 if ( scanner->token == '+' ) {
309 g_scanner_get_next_token (scanner);
310 if ( scanner->token == SYMBOL_CGSN ) {
311 g_scanner_get_next_token (scanner);
312 if (scanner->token == ':') {
313 g_scanner_peek_next_token (scanner);
314 if ( scanner->next_token == G_TOKEN_INT) {
315 res = g_strdup(response->str+g_scanner_cur_position(scanner));
316 res = g_strstrip(res);
320 } else {
321 res = g_strdup(response->str);
322 res = g_strstrip(res);
324 if ( res ) {
325 gboolean is_imei = TRUE;
326 gint i = 0;
327 if ( strlen(res) == 15 ) {
328 for (i=0; i < 15;i++) {
329 if ( !g_ascii_isdigit(res[i]) ) {
330 is_imei = FALSE;
331 break;
334 } else {
335 is_imei = FALSE;
337 if ( !is_imei ) {
338 g_debug("%s : %s is not IMEI",__func__, res);
339 g_free( res );
340 return AT_HANDLER_DONT_UNDERSTAND;
343 g_debug("%s : IMEI: %s",__func__, res);
345 gsmd_utils_table_insert_string(at->handler_data,GSMD_DEVICE_KEY_IMEI,res);
347 g_free( res );
349 return AT_HANDLER_NEED_MORE;
351 static
352 AtCommandHandlerStatus gsmd_device_handler_query_revision (ModemInterface *modem,
353 AtCommandContext *at,
354 GString *response)
356 g_debug("%s : %s",__func__, response->str);
357 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
359 response,
360 GSMD_DEVICE_KEY_MODEM_REVISION,
361 "ERROR OCCURRED WHEN QUERYING REVISION",
362 "TIMEOUT OCCURRED WHEN QUERYING REVISION");
363 if (status != AT_HANDLER_DONT_UNDERSTAND)
364 return status;
367 GScanner* scanner = modem->scanner;
368 gchar *res = NULL;;
369 if ( scanner->token == '+' ) {
370 g_scanner_get_next_token (scanner);
371 if ( scanner->token == SYMBOL_CGMR ) {
372 g_scanner_get_next_token (scanner);
373 if (scanner->token == ':') {
374 g_scanner_peek_next_token (scanner);
375 if ( scanner->next_token == G_TOKEN_STRING ) {
376 g_scanner_get_next_token (scanner);
377 res = g_strdup(scanner->value.v_string);
378 } else {
379 res = g_strdup(response->str+g_scanner_cur_position(scanner));
380 res = g_strstrip(res);
382 g_debug("%s : manu: '%s'", __func__, res);
385 } else {
386 res = g_strdup(response->str);
387 res = g_strstrip(res);
389 if ( res && strlen(res) > 0 ) {
390 g_debug("%s : SW revision: %s",__func__, res);
391 gsmd_utils_table_insert_string(at->handler_data,
392 GSMD_DEVICE_KEY_MODEM_REVISION,
393 res);
396 g_free(res);
397 return AT_HANDLER_NEED_MORE;
399 static
400 AtCommandHandlerStatus gsmd_device_handler_query_manufacturer (ModemInterface *modem,
401 AtCommandContext *at,
402 GString *response)
404 /* g_debug("%s : %s",__func__, response->str); */
405 AtCommandHandlerStatus status = gsmd_device_get_info_handler(modem,
407 response,
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 response,
456 GSMD_DEVICE_KEY_MODEM_MODEL,
457 "ERROR OCCURRED WHEN QUERYING MODEL",
458 "TIMEOUT OCCURRED WHEN QUERYING MODEL");
459 if (status != AT_HANDLER_DONT_UNDERSTAND)
460 return status;
462 GScanner* scanner = modem->scanner;
463 gchar *res = NULL;;
464 if ( scanner->token == '+' ) {
465 g_scanner_get_next_token (scanner);
466 if ( scanner->token == SYMBOL_CGMM ) {
467 g_scanner_get_next_token (scanner);
468 if (scanner->token == ':') {
469 g_scanner_peek_next_token (scanner);
470 if ( scanner->next_token == G_TOKEN_STRING ) {
471 g_scanner_get_next_token (scanner);
472 res = g_strdup(scanner->value.v_string);
473 } else {
474 res = g_strdup(response->str+g_scanner_cur_position(scanner));
475 res = g_strstrip(res);
477 g_debug("%s : manu: '%s'", __func__, res);
480 } else {
481 res = g_strdup(response->str);
482 res = g_strstrip(res);
484 if ( res && strlen(res) > 0 ) {
485 g_debug("%s : model: %s",__func__, res);
486 gsmd_utils_table_insert_string(at->handler_data,
487 GSMD_DEVICE_KEY_MODEM_MODEL,
488 res);
490 g_free(res);
492 return AT_HANDLER_NEED_MORE;
496 static gboolean gsmd_device_command_get_info_reply(ModemInterface *modem,
497 gpointer ipc_data,
498 GHashTable *info)
500 if( !modem->no_cache ) {
501 GValue *vendor = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_VENDOR);
502 GValue *model = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_MODEL);
503 GValue *revision = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_REVISION);
504 GValue *imei = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_IMEI);
506 if (vendor) {
507 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_VENDOR,vendor);
509 if (model) {
510 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_MODEL,model);
512 if (revision) {
513 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_REVISION,revision);
515 if (imei) {
516 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_IMEI,imei);
519 modem->device_ipc->get_info_reply( modem->device_ipc,
520 ipc_data,
521 info);
522 return TRUE;
525 static
526 AtCommandHandlerStatus gsmd_device_handler_get_info (ModemInterface *modem,
527 AtCommandContext *at,
528 GString *response)
530 AtCommandHandlerStatus status = AT_HANDLER_DONT_UNDERSTAND;
531 AtCommandContext *cmd = NULL;
532 switch (at->command->cmd_id) {
533 case IMEI_QUERY:
534 g_debug("%s : IMEI_QUERY", __func__);
535 /* status = gsmd_device_handler_query_imei(modem,at,response); */
536 status = at->command->handler(modem,at,response);
537 switch (status) {
538 case AT_HANDLER_DONE_ERROR:
539 case AT_HANDLER_ERROR:
540 return AT_HANDLER_DONE_ERROR;
541 break;
542 case AT_HANDLER_DONE:
543 cmd = gsmd_at_command_context_new_from_id( modem,
544 MANUFACTURER_QUERY,
545 NULL,/*param*/
546 at->ipc_data,
547 at->error_function,
548 at->error_data,
549 at->handler_data);
550 at->handler_data = NULL;
551 cmd->handler = &gsmd_device_handler_get_info;
552 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
553 status = AT_HANDLER_DONE;
554 break;
555 case AT_HANDLER_DONT_UNDERSTAND:
556 case AT_HANDLER_NEED_MORE:
557 case AT_HANDLER_RETRY:
558 return status;
560 break;
561 case MANUFACTURER_QUERY:
562 g_debug("%s : MANUFACTURER_QUERY", __func__);
563 status = at->command->handler(modem,at,response);
564 switch (status) {
565 case AT_HANDLER_DONE_ERROR:
566 case AT_HANDLER_ERROR:
567 return AT_HANDLER_DONE_ERROR;
568 case AT_HANDLER_DONE:
569 cmd = gsmd_at_command_context_new_from_id( modem,
570 SW_REVISION_QUERY,
571 NULL,/*param*/
572 at->ipc_data,
573 at->error_function,
574 at->error_data,
575 at->handler_data);
576 at->handler_data = NULL;
577 cmd->handler = &gsmd_device_handler_get_info;
578 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
579 status = AT_HANDLER_DONE;
580 break;
581 case AT_HANDLER_DONT_UNDERSTAND:
582 case AT_HANDLER_NEED_MORE:
583 case AT_HANDLER_RETRY:
584 return status;
586 break;
587 case SW_REVISION_QUERY:
588 g_debug("%s : SW_REVISION_QUERY", __func__);
589 status = at->command->handler(modem,at,response);
590 switch (status) {
591 case AT_HANDLER_DONE_ERROR:
592 case AT_HANDLER_ERROR:
593 return AT_HANDLER_DONE_ERROR;
594 case AT_HANDLER_DONE:
595 cmd = gsmd_at_command_context_new_from_id( modem,
596 MODEL_QUERY,
597 NULL,/*param*/
598 at->ipc_data,
599 at->error_function,
600 at->error_data,
601 at->handler_data);
602 at->handler_data = NULL;
603 cmd->handler = &gsmd_device_handler_get_info;
604 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
605 status = AT_HANDLER_DONE;
606 break;
607 case AT_HANDLER_DONT_UNDERSTAND:
608 case AT_HANDLER_NEED_MORE:
609 case AT_HANDLER_RETRY:
610 return status;
612 break;
613 case MODEL_QUERY:
614 g_debug("%s : MODEL_QUERY", __func__);
615 status = gsmd_device_handler_query_model(modem,at,response);
616 switch (status) {
617 case AT_HANDLER_DONE_ERROR:
618 case AT_HANDLER_ERROR:
619 return AT_HANDLER_DONE_ERROR;
620 break;
621 case AT_HANDLER_DONE:
622 gsmd_device_command_get_info_reply(modem,at->ipc_data, at->handler_data);
624 break;
625 case AT_HANDLER_DONT_UNDERSTAND:
626 case AT_HANDLER_NEED_MORE:
627 case AT_HANDLER_RETRY:
628 return status;
630 break;
632 return status;
637 void gsmd_device_command_get_info( DeviceInterface *device, gpointer ipc_data)
639 ModemInterface *modem = (ModemInterface*)device->priv;
640 GValue *vendor = NULL;
641 GValue *model = NULL;
642 GValue *revision = NULL;
643 GValue *imei = NULL;
644 if ( !modem->no_cache ) {
645 vendor = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_VENDOR);
646 model = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_MODEL);
647 revision = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_MODEM_REVISION);
648 imei = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_IMEI);
650 if (vendor && model && revision && imei) {
651 g_debug("%s: info is cached",__func__);
652 GHashTable *info = gsmd_utils_create_hash_table();
653 gsmd_utils_table_insert_copy(info,GSMD_DEVICE_KEY_MODEM_VENDOR,vendor);
654 gsmd_utils_table_insert_copy(info,GSMD_DEVICE_KEY_MODEM_MODEL,model);
655 gsmd_utils_table_insert_copy(info,GSMD_DEVICE_KEY_MODEM_REVISION,revision);
656 gsmd_utils_table_insert_copy(info,GSMD_DEVICE_KEY_IMEI,imei);
657 modem->device_ipc->get_info_reply(modem->device_ipc,
658 ipc_data,
659 info);
660 g_hash_table_destroy(info);
662 } else {
663 AtCommandContext *cmd = NULL;
664 cmd = gsmd_at_command_context_new_from_id( modem,
665 IMEI_QUERY,
666 NULL,/*param*/
667 ipc_data,
668 (ErrorFunction)modem->device_ipc->get_info_error,
669 modem->device_ipc,
670 NULL);
671 cmd->handler = &gsmd_device_handler_get_info;
672 gsmd_modem_post_at_command(modem,cmd,INTERFACE_DEVICE);
677 void gsmd_device_command_set_antenna_power( DeviceInterface *device,
678 gpointer ipc_data,
679 gboolean antenna_power)
681 //TODO implement
685 static
686 AtCommandHandlerStatus gsmd_device_handler_get_antenna_power (ModemInterface *modem,
687 AtCommandContext *at,
688 GString *response)
690 GScanner* scanner = modem->scanner;
691 GValue *val = NULL;
692 // g_message ("Query datatime handler\n");
693 //AT+CCLK=?
694 // +CCLK: "02/09/07,22:30:25"
695 if (scanner->token == SYMBOL_OK) {
696 val = g_hash_table_lookup(at->handler_data,GSMD_DEVICE_KEY_POWER);
699 if (!val) {
700 g_warning("%s : Invalid handler data. power: %p",
701 __func__,
702 val);
704 gsmd_utils_send_error(at,
705 GSMD_ERROR_UNKNOWN,
706 "OK WITHOUT RESPONSE");
710 if (!val)
711 return AT_HANDLER_DONE_ERROR;
714 modem->device_ipc->get_antenna_power_reply(modem->device_ipc,
715 at->ipc_data,
716 g_value_get_boolean(val));
718 gsmd_utils_table_insert_copy(modem->caches[INTERFACE_DEVICE],
719 GSMD_DEVICE_KEY_POWER,
720 val);
721 return AT_HANDLER_DONE;
725 if (gsmd_utils_send_error_from_response(at,
726 response,
727 "FAILED TO GET ANTENNA POWER",
728 "TIMEOUT WHEN GETTING ANTENNA POWER")) {
729 return AT_HANDLER_DONE_ERROR;
732 if (scanner->token != '+') {
733 return AT_HANDLER_DONT_UNDERSTAND;
735 g_scanner_get_next_token (scanner);
736 if (scanner->token == SYMBOL_CFUN) {
737 g_scanner_get_next_token (scanner);//get :
738 g_scanner_get_next_token (scanner);//get string
740 gsmd_utils_table_insert_boolean(at->handler_data,
741 GSMD_DEVICE_KEY_POWER,
742 scanner->value.v_int);
743 return AT_HANDLER_NEED_MORE;
745 return AT_HANDLER_DONT_UNDERSTAND;
748 void gsmd_device_command_get_antenna_power( DeviceInterface *device,
749 gpointer ipc_data)
751 ModemInterface *modem = (ModemInterface*)device->priv;
752 if (modem->no_cache || !g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_POWER)) {
753 gsmd_modem_post_at_command_id( modem,
754 ANTENNA_POWER_GET,
755 NULL,
756 ipc_data,
757 (ErrorFunction)modem->device_ipc->get_antenna_power_error,
758 (gpointer)modem->device_ipc,
759 INTERFACE_DEVICE,
760 NULL);
761 } else {
762 GValue *val = g_hash_table_lookup(modem->caches[INTERFACE_DEVICE],GSMD_DEVICE_KEY_POWER);
763 if (val) {
764 modem->device_ipc->get_antenna_power_reply(modem->device_ipc,
765 ipc_data,
766 g_value_get_boolean(val));
773 void gsmd_device_command_prepare_to_suspend( DeviceInterface *device,
774 gpointer ipc_data)
776 ModemInterface *modem = (ModemInterface*)device->priv;
777 modem->device_ipc->prepare_to_suspend_reply(modem->device_ipc,
778 ipc_data);
781 void gsmd_device_command_recover_from_suspend( DeviceInterface *device,
782 gpointer ipc_data)
784 ModemInterface *modem = (ModemInterface*)device->priv;
785 modem->device_ipc->recover_from_suspend_reply(modem->device_ipc,
786 ipc_data);
789 void gsmd_device_command_get_features( DeviceInterface *device, gpointer ipc_data)
791 ModemInterface *modem = (ModemInterface*)device->priv;
792 GHashTable *table = gsmd_utils_create_hash_table();
794 modem->device_ipc->get_features_reply( modem->device_ipc,
795 ipc_data,
796 table);
797 g_hash_table_destroy(table);
801 void gsmd_device_init(ModemInterface *modem)
803 gsmd_device_init_at_handler(modem);
805 modem->device->priv = (gpointer)modem;
806 modem->device->prepare_to_suspend = &gsmd_device_command_prepare_to_suspend;
807 modem->device->recover_from_suspend = &gsmd_device_command_recover_from_suspend;
808 modem->device->get_date_time = &gsmd_device_command_query_date_time;
809 modem->device->set_date_time = &gsmd_device_command_set_date_time;
810 modem->device->get_info = &gsmd_device_command_get_info;
811 modem->device->set_antenna_power = &gsmd_device_command_set_antenna_power;
812 modem->device->get_antenna_power = &gsmd_device_command_get_antenna_power;
813 modem->device->get_features = &gsmd_device_command_get_features;