gisi: Refactor indication subscriptions
authorAki Niemi <aki.niemi@nokia.com>
Fri, 4 Feb 2011 12:58:04 +0000 (14:58 +0200)
committerAki Niemi <aki.niemi@nokia.com>
Mon, 7 Feb 2011 07:51:35 +0000 (09:51 +0200)
Handle different message types for IND subscriptions based on the
presence of the GISI_MODEM_FLAG_USE_LEGACY_SUBSCRIBE flag. This
enables building modem plugins for modems that only support one or the
other available IND types.

Based on patches from:
Jessica Nilsson <jessica.j.nilsson@stericsson.com>

gisi/common.h
gisi/modem.c

index cadd3f4..a29e6fa 100644 (file)
@@ -35,6 +35,7 @@ enum message_id {
        PNS_NAME_ADD_REQ =                      0x05,
        PNS_NAME_REMOVE_REQ =                   0x07,
        PNS_SUBSCRIBED_RESOURCES_IND =          0x10,
+       PNS_SUBSCRIBED_RESOURCES_EXTEND_IND =   0x12,
        COMM_ISI_VERSION_GET_REQ =              0x12,
        COMM_ISI_VERSION_GET_RESP =             0x13,
        COMM_ISA_ENTITY_NOT_REACHABLE_RESP =    0x14,
index 9caa2a9..f745bb2 100644 (file)
@@ -341,16 +341,21 @@ static gboolean modem_subs_update(gpointer data)
        gpointer keyptr, value;
 
        GIsiModem *modem = data;
+       gboolean legacy = modem->flags & GISI_MODEM_FLAG_USE_LEGACY_SUBSCRIBE;
        struct sockaddr_pn commgr = {
                .spn_family = AF_PHONET,
                .spn_resource = PN_COMMGR,
                .spn_dev = modem->device,
        };
-       uint8_t msg[3 + 256] = {
-               0, PNS_SUBSCRIBED_RESOURCES_IND,
-               0,
+       uint8_t msg[4 + 1024] = {
+               0,      /* UTID */
+               legacy ? PNS_SUBSCRIBED_RESOURCES_IND :
+                       PNS_SUBSCRIBED_RESOURCES_EXTEND_IND,
+               0,      /* Count */
+               0,      /* Filler */
        };
        uint8_t count = 0;
+       size_t len;
 
        modem->subs_source = 0;
 
@@ -359,14 +364,22 @@ static gboolean modem_subs_update(gpointer data)
        while (g_hash_table_iter_next(&iter, &keyptr, &value)) {
                GIsiServiceMux *mux = value;
 
-               if (mux->subscriptions > 0) {
+               if (mux->subscriptions == 0)
+                       continue;
+
+               if (legacy)
                        msg[3 + count] = mux->resource;
-                       count++;
-               }
+               else
+                       /* Resource field is 32bit and Little-endian */
+                       msg[4 + count * 4 + 3] = mux->resource;
+
+               count++;
        }
+
+       len = legacy ? 3 + count : 4 + count * 4;
        msg[2] = count;
 
-       sendto(modem->ind_fd, msg, 3 + msg[2], MSG_NOSIGNAL, (void *)&commgr,
+       sendto(modem->ind_fd, msg, len, MSG_NOSIGNAL, (void *) &commgr,
                sizeof(commgr));
 
        return FALSE;