Gsmd/document

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(What is gsmd)
(-cat)
 
(15 intermediate revisions by 8 users not shown)
Line 9: Line 9:
  
 
== Gsmd ==
 
== Gsmd ==
GSMD is a event driven daemon. Each event shall has a response.
+
GSMD is an event-driven daemon. Each event shall have a response and will pass through the function '''gsmd_select_main()''' in which finding and then executing their correspond callback functions.
Every event will pass through the '''gsmd_select_main()''' in which finding and executing their correspond call back functions.
+
  
 
The last part of gsmd '''main''' function enters a infinite loop, trying to call '''gsmd_select_main'''.
 
The last part of gsmd '''main''' function enters a infinite loop, trying to call '''gsmd_select_main'''.
Line 18: Line 17:
 
           ...
 
           ...
 
   }
 
   }
 +
 +
=== Design Policy ===
 +
* All commands will wait synchronously for a response until timeout.
 +
* All callback functions of commands with multiple-line responses are re-entrant.
 +
* Commands of specific modem will be put in vendor plug-in.
 +
* Commands or some special scheme for specific platform will be put in machine plug-in.
  
 
=== gsmd_select_main() ===
 
=== gsmd_select_main() ===
gsmd_select_main this is core of the call back function scheme. All devices, gsmd monitors and linked in a [http://wiki.kldp.org/wiki.php/LinkedList list], are described as a struct '''gsmd_fd''', and gsmd_select_main will [http://swoolley.org/man.cgi/select select] them.  
+
gsmd_select_main this is core of the callback function scheme. All devices, gsmd monitors and linked in a [http://wiki.kldp.org/wiki.php/LinkedList list], are described as a struct '''gsmd_fd''', and gsmd_select_main will [http://swoolley.org/man.cgi/select select] them.  
Once an event comes out from one of the devices, gsmd_select_main will try to call it's '''call back function''' that devices registered.
+
Once an event comes out from one of the devices, gsmd_select_main will try to call it's '''callback function''' that devices registered.
  
 
  int gsmd_select_main()
 
  int gsmd_select_main()
Line 77: Line 82:
 
  };
 
  };
  
When there are anything change in fd, the gsmd_select_main will detect them and try to call it's call back function cb.
+
When there are anything change in fd, the gsmd_select_main will detect them and try to call it's callback function cb.
  
That means if you redirect the cb to another implementation, the gsmd will behave very differently.
+
That means if you redirect the callback function cb to another implementation, the gsmd will behave very differently.
  
 
==== gsmd_atcmd ====
 
==== gsmd_atcmd ====
Line 95: Line 100:
 
  };
 
  };
  
=== call back functions ===
+
=== callback functions ===
 
Gsmd opens at least one devices. One is uart to modem and others are the Unix socket, communicating with libgsmd.
 
Gsmd opens at least one devices. One is uart to modem and others are the Unix socket, communicating with libgsmd.
 
   
 
   
'''atcmd_select_cb''' is the default call back function that dealing the uart to the modem. It will handle sending AT command to modem or receive whatever return from modem and send them into parser.  
+
'''atcmd_select_cb''' is the default callback function that dealing the UART to the modem. It will handle sending AT commands to GSM modem or receive whatever return from modem and send them into parser.  
  
The default parser call back function of uart (to modem) is '''ml_parse''', in which dealing with reading the response of modem dispatch the correct call back function to handle the response.
+
The default parser callback function of UART (to modem) is '''ml_parse''', in which dealing with reading the response from modem and dispatching the correct callback function to handle the response.
 
   
 
   
 
==== atcmd_select_cb ====
 
==== atcmd_select_cb ====
 +
There are two queues that handles the atcmds. One is pending_atcmds, and the other is busy_atcmds.
 +
pending_atcmds links all the atcmds user send to gsmd in sequence and those commands are not send to modem yet.
 +
busy_atcmds links all the atcmds sent to gsm modem but not get the response yet.
 +
Both pending_atcmds and busy_atcmds are FIFO queue.
  
 +
There are two mode of atcmd_select_cb "GSMD_FD_READ" and "GSMD_FD_WRITE".  If there are data come out from uart, atcmd_select_cb will be called in READ mode. It will try to read the data from uart and put them llparser_string.  llparser_string will try to use the actual parser implementation set by gsmd. (default is ml_parser)
 +
 +
If there are atcmds in pending_atcmds queue, the atcmd_select_cb will be called in WRITE mode. It will try to write the atcmd at the head of queue to modem, and move this atcmd handler into busy_atcmds queue.
 
===== atcmd_fill =====
 
===== atcmd_fill =====
  
Line 109: Line 121:
  
 
==== ml_parse ====
 
==== ml_parse ====
ml_parse is the parser call back function that handles:
+
ml_parse is the parser callback function that handles:
 
* Initial GSM Modem
 
* Initial GSM Modem
* handle correspond AT command call back
+
* Handle an information response ("+whatever: ...")
* handle notification call back
+
* Handle an unsolicited message ("+whateverelse: ... ")
 +
* Handle a final response ("OK", "+CME ERROR", ...)
 +
* Handle an intermediate response ("CONNECTED", "BUSY", "NO DIALTONE")
  
===== initial GSM Modem =====
+
===== Initialize GSM Modem =====
 
When the modem firmware is ready to initial, it will send '''AT-Command Interpreter ready''' to gsmd. If ml_parse get this string, gsmd will try to initialize the modem.
 
When the modem firmware is ready to initial, it will send '''AT-Command Interpreter ready''' to gsmd. If ml_parse get this string, gsmd will try to initialize the modem.
 
         if (strlen(buf) == 0 ||
 
         if (strlen(buf) == 0 ||
Line 127: Line 141:
 
gsmd_alive_start is a scheme that gsmd detect if the modem is still alive or not. It will send an "AT" to modem periodically, and check the modem's response.
 
gsmd_alive_start is a scheme that gsmd detect if the modem is still alive or not. It will send an "AT" to modem periodically, and check the modem's response.
  
===== handle correspond AT command call back =====
+
If modem does not send out "AT-Command Interpreter ready", gsmd will still be initialized by the callback function (firstcmd_atcb) of ATZ.
===== handle notification call back =====
+
  
 
== libgsmd ==
 
== libgsmd ==
Line 221: Line 234:
 
== Debug Log ==
 
== Debug Log ==
 
== To-do ==
 
== To-do ==
 +
* Engineer Mode
 +
* Timeout Scheme
 +
* Mux
 +
* Stable GSMD Initial Flow
 +
* API fix
 +
 +
[[Category:GSM]]

Latest revision as of 09:15, 19 July 2009

Contents

[edit] Overview

[edit] What is gsmd

Gsmd is a daemon that handles the communications between applications and GSM modem. Applications manipulate gsmd through the APIs defined in libgsmd. libgsmd communicates with gsmd through unix socket, and modem goes through UART. The diagram is as following.

http://lh6.google.com/ticktock35/RwDCAWdUPEI/AAAAAAAAAD4/wBrRLv-1oyE/s400/gsmd_overview.jpg

[edit] Gsmd

GSMD is an event-driven daemon. Each event shall have a response and will pass through the function gsmd_select_main() in which finding and then executing their correspond callback functions.

The last part of gsmd main function enters a infinite loop, trying to call gsmd_select_main.

while(1) {
         int ret = gsmd_select_main();
         ...
 }

[edit] Design Policy

  • All commands will wait synchronously for a response until timeout.
  • All callback functions of commands with multiple-line responses are re-entrant.
  • Commands of specific modem will be put in vendor plug-in.
  • Commands or some special scheme for specific platform will be put in machine plug-in.

[edit] gsmd_select_main()

gsmd_select_main this is core of the callback function scheme. All devices, gsmd monitors and linked in a list, are described as a struct gsmd_fd, and gsmd_select_main will select them. Once an event comes out from one of the devices, gsmd_select_main will try to call it's callback function that devices registered.

int gsmd_select_main()
{
       struct gsmd_fd *ufd, *ufd2;
       fd_set readset, writeset, exceptset;
       int i;

       FD_ZERO(&readset);
       FD_ZERO(&writeset);
       FD_ZERO(&exceptset);

       /* prepare read and write fdsets */
       llist_for_each_entry(ufd, &gsmd_fds, list) {
               if (ufd->when & GSMD_FD_READ)
                       FD_SET(ufd->fd, &readset);

               if (ufd->when & GSMD_FD_WRITE)
                       FD_SET(ufd->fd, &writeset);

               if (ufd->when & GSMD_FD_EXCEPT)
                       FD_SET(ufd->fd, &exceptset);
       }

       i = select(maxfd+1, &readset, &writeset, &exceptset, NULL);
       if (i > 0) {
               /* call registered callback functions */
               llist_for_each_entry_safe(ufd, ufd2, &gsmd_fds, list) {
                       int flags = 0;

                       if (FD_ISSET(ufd->fd, &readset))
                               flags |= GSMD_FD_READ;

                       if (FD_ISSET(ufd->fd, &writeset))
                               flags |= GSMD_FD_WRITE;
 
                       if (FD_ISSET(ufd->fd, &exceptset))
                               flags |= GSMD_FD_EXCEPT;

                       if (flags)
                               ufd->cb(ufd->fd, flags, ufd->data);
               }
       }
       return i;
}


[edit] gsmd_fd

struct gsmd_fd {
    struct llist_head list;
    int fd;                         /* file descriptor */
    unsigned int when;
    int (*cb)(int fd, unsigned int what, void *data);
    void *data;                     /* void * to pass to callback */
};

When there are anything change in fd, the gsmd_select_main will detect them and try to call it's callback function cb.

That means if you redirect the callback function cb to another implementation, the gsmd will behave very differently.

[edit] gsmd_atcmd

struct gsmd_atcmd {
       struct llist_head list;
       void *ctx;
       int (*cb)(struct gsmd_atcmd *cmd, void *ctx, char *resp);
       char *resp;
       int32_t ret;
       u_int32_t buflen;
       u_int16_t id;
       u_int8_t flags;
       char *cur;
       char buf[];
};

[edit] callback functions

Gsmd opens at least one devices. One is uart to modem and others are the Unix socket, communicating with libgsmd.

atcmd_select_cb is the default callback function that dealing the UART to the modem. It will handle sending AT commands to GSM modem or receive whatever return from modem and send them into parser.

The default parser callback function of UART (to modem) is ml_parse, in which dealing with reading the response from modem and dispatching the correct callback function to handle the response.

[edit] atcmd_select_cb

There are two queues that handles the atcmds. One is pending_atcmds, and the other is busy_atcmds. pending_atcmds links all the atcmds user send to gsmd in sequence and those commands are not send to modem yet. busy_atcmds links all the atcmds sent to gsm modem but not get the response yet. Both pending_atcmds and busy_atcmds are FIFO queue.

There are two mode of atcmd_select_cb "GSMD_FD_READ" and "GSMD_FD_WRITE". If there are data come out from uart, atcmd_select_cb will be called in READ mode. It will try to read the data from uart and put them llparser_string. llparser_string will try to use the actual parser implementation set by gsmd. (default is ml_parser)

If there are atcmds in pending_atcmds queue, the atcmd_select_cb will be called in WRITE mode. It will try to write the atcmd at the head of queue to modem, and move this atcmd handler into busy_atcmds queue.

[edit] atcmd_fill
[edit] atcmd_submit

[edit] ml_parse

ml_parse is the parser callback function that handles:

  • Initial GSM Modem
  • Handle an information response ("+whatever: ...")
  • Handle an unsolicited message ("+whateverelse: ... ")
  • Handle a final response ("OK", "+CME ERROR", ...)
  • Handle an intermediate response ("CONNECTED", "BUSY", "NO DIALTONE")
[edit] Initialize GSM Modem

When the modem firmware is ready to initial, it will send AT-Command Interpreter ready to gsmd. If ml_parse get this string, gsmd will try to initialize the modem.

       if (strlen(buf) == 0 ||
           !strcmp(buf, "AT-Command Interpreter ready")) {
               g->interpreter_ready = 1;
               gsmd_initsettings(g);
               gmsd_alive_start(g);
               return 0;
       }

What modem write to gsmd will put in "buf". And if the contents of the "buf" is "AT-Command Interpreter ready" the automatic gsmd initialize will start.

gsmd_alive_start is a scheme that gsmd detect if the modem is still alive or not. It will send an "AT" to modem periodically, and check the modem's response.

If modem does not send out "AT-Command Interpreter ready", gsmd will still be initialized by the callback function (firstcmd_atcb) of ATZ.

[edit] libgsmd

libgsmd is a library with C language API for application programs. Programs using this library can use the phone, e.g. make phone calls, receive incoming calls, register to the network, etc.

[edit] libgsmd_sms

libgsmd_sms is about all related SMS functions. The API is as below:

  • List Messages: can list all SMS message by 'stat' value
extern int lgsm_sms_list(struct lgsm_handle *lh, enum gsmd_msg_sms_type stat);


  • Read Message: It can read one SMS message by 'index' value
extern int lgsm_sms_read(struct lgsm_handle *lh, int index);


  • Delete Message: can delete one SMS message by 'index' and 'del_flag' values
extern int lgsm_sms_delete(struct lgsm_handle *lh, const struct lgsm_sms_delete *sms_del);


  • Send Message: can send one SMS message
extern int lgsm_sms_send (struct lgsm_handle *lh, const struct lgsm_sms *sms);


  • Write Message to Memory: can write one SMS message to preferred memory
extern int lgsm_sms_write (struct lgsm_handle *lh, const struct lgsm_sms_write *sms_write);


  • Retrieve SMS storage Information: retrieve all SMS storage information
extern int lgsm_sms_get_storage (struct lgsm_handle *lh);


  • Set preferred SMS storage: can set SMS preferred storage
extern int lgsm_sms_set_storage (struct lgsm_handle *lh, enum ts0705_mem_type mem1, enum ts0705_mem_type mem2, enum ts0705_mem_type mem3);


  • Retrieve current default service center address
extern int lgsm_sms_get_smsc(struct lgsm_handle *lh);


  • Set new default service center address
extern int lgsm_sms_set_smsc(struct lgsm_handle *lh, const char *number);


  • Packing of 7-bit characters
extern int packing_7bit_character(const char *src, struct lgsm_sms *dest);


[edit] libgsmd_phonebook

libgsmd_phonebook is about all related phonebook functions. The API is as below:

  • Store a specific phonebook entry 'pb' into phone
extern int lgsm_pb_set_entry(struct lgsm_handle *lh, struct lgsm_pb_entry *pb);


  • List of supported phonebook memory storage
extern int lgsm_pb_list_storage(struct lgsm_handle *lh);


  • Select phonebook memory storage
extern int lgsm_pb_set_storage(struct lgsm_handle *lh, char *storage);


  • Find phonebook entires which alphanumeric filed start with string <findtext>
extern int lgsm_pb_find_entry(struct lgsm_handle *lh, const struct lgsm_phonebook_find *pb_find);


  • Read phonebook entry in location number index
extern int lgsm_pb_read_entry(struct lgsm_handle *lh, int index);


  • Read phonebook entries in location number range
extern int lgsm_pb_read_entries(struct lgsm_handle *lh, const struct lgsm_phonebook_readrg *pb_readrg);


  • Delete phonebook entry in location index
extern int lgsm_pb_del_entry(struct lgsm_handle *lh, int index);


  • Write phonebook entry in location
extern int lgsm_pb_write_entry(struct lgsm_handle *lh, const struct lgsm_phonebook *pb);


  • Get the location range/nlength/tlength supported
extern int lgsm_pb_get_support(struct lgsm_handle *lh);

[edit] libgsmd-tool

Please reference to here

[edit] Debug Log

[edit] To-do

  • Engineer Mode
  • Timeout Scheme
  • Mux
  • Stable GSMD Initial Flow
  • API fix
Personal tools

Overview

What is gsmd

Gsmd is a daemon that handles the communications between applications and GSM modem. Applications manipulate gsmd through the APIs defined in libgsmd. libgsmd communicates with gsmd through unix socket, and modem goes through UART. The diagram is as following.

http://lh6.google.com/ticktock35/RwDCAWdUPEI/AAAAAAAAAD4/wBrRLv-1oyE/s400/gsmd_overview.jpg

Gsmd

GSMD is a event driven daemon. Each event shall has a response. Every event will pass through the gsmd_select_main() in which finding and executing their correspond call back functions.

The last part of gsmd main function enters a infinite loop, trying to call gsmd_select_main.

while(1) {
         int ret = gsmd_select_main();
         ...
 }

gsmd_select_main()

gsmd_select_main this is core of the call back function scheme. All devices, gsmd monitors and linked in a list, are described as a struct gsmd_fd, and gsmd_select_main will select them. Once an event comes out from one of the devices, gsmd_select_main will try to call it's call back function that devices registered.

int gsmd_select_main()
{
       struct gsmd_fd *ufd, *ufd2;
       fd_set readset, writeset, exceptset;
       int i;

       FD_ZERO(&readset);
       FD_ZERO(&writeset);
       FD_ZERO(&exceptset);

       /* prepare read and write fdsets */
       llist_for_each_entry(ufd, &gsmd_fds, list) {
               if (ufd->when & GSMD_FD_READ)
                       FD_SET(ufd->fd, &readset);

               if (ufd->when & GSMD_FD_WRITE)
                       FD_SET(ufd->fd, &writeset);

               if (ufd->when & GSMD_FD_EXCEPT)
                       FD_SET(ufd->fd, &exceptset);
       }

       i = select(maxfd+1, &readset, &writeset, &exceptset, NULL);
       if (i > 0) {
               /* call registered callback functions */
               llist_for_each_entry_safe(ufd, ufd2, &gsmd_fds, list) {
                       int flags = 0;

                       if (FD_ISSET(ufd->fd, &readset))
                               flags |= GSMD_FD_READ;

                       if (FD_ISSET(ufd->fd, &writeset))
                               flags |= GSMD_FD_WRITE;
 
                       if (FD_ISSET(ufd->fd, &exceptset))
                               flags |= GSMD_FD_EXCEPT;

                       if (flags)
                               ufd->cb(ufd->fd, flags, ufd->data);
               }
       }
       return i;
}


gsmd_fd

struct gsmd_fd {
    struct llist_head list;
    int fd;                         /* file descriptor */
    unsigned int when;
    int (*cb)(int fd, unsigned int what, void *data);
    void *data;                     /* void * to pass to callback */
};

When there are anything change in fd, the gsmd_select_main will detect them and try to call it's call back function cb.

That means if you redirect the cb to another implementation, the gsmd will behave very differently.

gsmd_atcmd

struct gsmd_atcmd {
       struct llist_head list;
       void *ctx;
       int (*cb)(struct gsmd_atcmd *cmd, void *ctx, char *resp);
       char *resp;
       int32_t ret;
       u_int32_t buflen;
       u_int16_t id;
       u_int8_t flags;
       char *cur;
       char buf[];
};

call back functions

Gsmd opens at least one devices. One is uart to modem and others are the Unix socket, communicating with libgsmd.

atcmd_select_cb is the default call back function that dealing the uart to the modem. It will handle sending AT command to modem or receive whatever return from modem and send them into parser.

The default parser call back function of uart (to modem) is ml_parse, in which dealing with reading the response of modem dispatch the correct call back function to handle the response.

atcmd_select_cb

atcmd_fill
atcmd_submit

ml_parse

ml_parse is the parser call back function that handles:

  • Initial GSM Modem
  • handle correspond AT command call back
  • handle notification call back
initial GSM Modem

When the modem firmware is ready to initial, it will send AT-Command Interpreter ready to gsmd. If ml_parse get this string, gsmd will try to initialize the modem.

       if (strlen(buf) == 0 ||
           !strcmp(buf, "AT-Command Interpreter ready")) {
               g->interpreter_ready = 1;
               gsmd_initsettings(g);
               gmsd_alive_start(g);
               return 0;
       }

What modem write to gsmd will put in "buf". And if the contents of the "buf" is "AT-Command Interpreter ready" the automatic gsmd initialize will start.

gsmd_alive_start is a scheme that gsmd detect if the modem is still alive or not. It will send an "AT" to modem periodically, and check the modem's response.

handle correspond AT command call back
handle notification call back

libgsmd

libgsmd is a library with C language API for application programs. Programs using this library can use the phone, e.g. make phone calls, receive incoming calls, register to the network, etc.

libgsmd_sms

libgsmd_sms is about all related SMS functions. The API is as below:

  • List Messages: can list all SMS message by 'stat' value
extern int lgsm_sms_list(struct lgsm_handle *lh, enum gsmd_msg_sms_type stat);


  • Read Message: It can read one SMS message by 'index' value
extern int lgsm_sms_read(struct lgsm_handle *lh, int index);


  • Delete Message: can delete one SMS message by 'index' and 'del_flag' values
extern int lgsm_sms_delete(struct lgsm_handle *lh, const struct lgsm_sms_delete *sms_del);


  • Send Message: can send one SMS message
extern int lgsm_sms_send (struct lgsm_handle *lh, const struct lgsm_sms *sms);


  • Write Message to Memory: can write one SMS message to preferred memory
extern int lgsm_sms_write (struct lgsm_handle *lh, const struct lgsm_sms_write *sms_write);


  • Retrieve SMS storage Information: retrieve all SMS storage information
extern int lgsm_sms_get_storage (struct lgsm_handle *lh);


  • Set preferred SMS storage: can set SMS preferred storage
extern int lgsm_sms_set_storage (struct lgsm_handle *lh, enum ts0705_mem_type mem1, enum ts0705_mem_type mem2, enum ts0705_mem_type mem3);


  • Retrieve current default service center address
extern int lgsm_sms_get_smsc(struct lgsm_handle *lh);


  • Set new default service center address
extern int lgsm_sms_set_smsc(struct lgsm_handle *lh, const char *number);


  • Packing of 7-bit characters
extern int packing_7bit_character(const char *src, struct lgsm_sms *dest);


libgsmd_phonebook

libgsmd_phonebook is about all related phonebook functions. The API is as below:

  • Store a specific phonebook entry 'pb' into phone
extern int lgsm_pb_set_entry(struct lgsm_handle *lh, struct lgsm_pb_entry *pb);


  • List of supported phonebook memory storage
extern int lgsm_pb_list_storage(struct lgsm_handle *lh);


  • Select phonebook memory storage
extern int lgsm_pb_set_storage(struct lgsm_handle *lh, char *storage);


  • Find phonebook entires which alphanumeric filed start with string <findtext>
extern int lgsm_pb_find_entry(struct lgsm_handle *lh, const struct lgsm_phonebook_find *pb_find);


  • Read phonebook entry in location number index
extern int lgsm_pb_read_entry(struct lgsm_handle *lh, int index);


  • Read phonebook entries in location number range
extern int lgsm_pb_read_entries(struct lgsm_handle *lh, const struct lgsm_phonebook_readrg *pb_readrg);


  • Delete phonebook entry in location index
extern int lgsm_pb_del_entry(struct lgsm_handle *lh, int index);


  • Write phonebook entry in location
extern int lgsm_pb_write_entry(struct lgsm_handle *lh, const struct lgsm_phonebook *pb);


  • Get the location range/nlength/tlength supported
extern int lgsm_pb_get_support(struct lgsm_handle *lh);

libgsmd-tool

Please reference to here

Debug Log

To-do