Reply functions

When phone gives answers, we check if we requested received info and we redirect it to concrete reply function, which will decode it. Different phone answers can go to one reply function let’s say responsible for getting sms status.

type GSM_Reply_Function

Defines reply function for phone driver.

GSM_Error (*Function)(GSM_Protocol_Message *msg, GSM_StateMachine *s);

Callback on reply match.

const unsigned char *msgtype;

String match on the message.

const size_t subtypechar;

Position for char match inside reply. If 0, message type is checked.

const int subtype;

Match for char/message type check (see above).

const GSM_Phone_RequestID requestID;

Match for request ID. this is filled in when calling GSM_WaitFor().

There are three types of answer matching:




ID_SaveSMSMessage request function reply. Frame is type “x14”, 0x03 char of frame must be 0x05. If yes, we go to N6110_ReplySaveSMSMessage. Of course, things like frame type are found in protocol (here FBUS, MBUS, etc.) functions. If don’t need anything more than frame type, 0x03,0x05 should be 0x00, 0x00 - it means then, that we check only frame type.




All incoming (not requested in the moment, sent by phone, who likes us - ID_IncomingFrame) responses starting from “+CLIP” will go to the ATGEN_ReplyIncomingCallInfo.



{S60_Reply_Generic, "", 0x00, NUM_QUIT, ID_Terminate },

When match string is empty and match char position is zero, matching on message type is performed.


This is how GSM_Reply_Function is filled. Now how to make phone requests ?


static GSM_Error N6110_GetMemory (GSM_StateMachine   *s,
                                 GSM_PhonebookEntry *entry)
  unsigned char req[] = {
       N6110_FRAME_HEADER, 0x01,
       0x00,            /* memory type */
       0x00,            /* location */

  req[4] = NOKIA_GetMemoryType(entry->MemoryType,N6110_MEMORY_TYPES);
  if (req[4]==0xff) return GE_NOTSUPPORTED;

  req[5] = entry->Location;

  dprintf("Getting phonebook entry\n");
  return GSM_WaitFor (s, req, 7, 0x03, 4, ID_GetMemory);

First we fill req according to values in *entry. Later set pointer in s->Phone.Data (it’s available for reply functions and they set responses exactly to it) and use GSM_WaitFor. It uses s statemachine, sends req frame with length 7, msg type is 0x03, we wait for answer during 4 seconds, request id is ID_GetMemory. GSM_WaitFor internally checks incoming bytes from phone and redirect them to protocol functions. If they found full frame, there is checked GSM_Reply_Function, where is called ReplyFunction or showed debug info, that frame is unknown. If there is ReplyFunction, it has access to s->Phone.Data and decodes answer. Returns error or not (and this is value for GSM_WaitFor). If there is no requested answer during time, GSM_WaitFor returns GE_TIMEOUT.