Add isimodem support for network time
authorAki Niemi <aki.niemi@nokia.com>
Tue, 18 May 2010 16:28:31 +0000 (19:28 +0300)
committerAki Niemi <aki.niemi@nokia.com>
Wed, 19 May 2010 07:46:33 +0000 (10:46 +0300)
drivers/isimodem/debug.c
drivers/isimodem/network-registration.c
drivers/isimodem/network.h

index 3ba9d52..86530fd 100644 (file)
@@ -744,6 +744,7 @@ const char *net_message_id_name(enum net_message_id value)
                _(NET_RSSI_GET_REQ);
                _(NET_RSSI_GET_RESP);
                _(NET_RSSI_IND);
+               _(NET_TIME_IND);
                _(NET_RAT_IND);
                _(NET_RAT_REQ);
                _(NET_RAT_RESP);
@@ -768,6 +769,7 @@ const char *net_subblock_name(enum net_subblock value)
                _(NET_GSM_REG_INFO);
                _(NET_DETAILED_NETWORK_INFO);
                _(NET_GSM_OPERATOR_INFO);
+               _(NET_TIME_INFO);
                _(NET_GSM_BAND_INFO);
                _(NET_RAT_INFO);
                _(NET_AVAIL_NETWORK_INFO_COMMON);
index eddf6fd..75dd6bc 100644 (file)
@@ -746,6 +746,44 @@ static void rssi_ind_cb(GIsiClient *client, const void *restrict data,
        ofono_netreg_strength_notify(netreg, msg[1]);
 }
 
+static void time_ind_cb(GIsiClient *client, const void *restrict data,
+                       size_t len, uint16_t object, void *opaque)
+{
+       const unsigned char *msg = data;
+       const unsigned char *nitz = msg + 3;
+       struct ofono_netreg *netreg = opaque;
+
+       struct ofono_network_time info;
+
+       if (!msg || len < 13 || msg[0] != NET_TIME_IND
+               || nitz[0] != NET_TIME_INFO)
+               return;
+
+       nitz += 2;
+
+       /* Value is years since last turn of century */
+       info.year = nitz[0] != NET_INVALID_TIME ? nitz[0] : -1;
+       info.year += 2000;
+
+       info.mon = nitz[1] != NET_INVALID_TIME ? nitz[1] : -1;
+       info.mday = nitz[2] != NET_INVALID_TIME ? nitz[2] : -1;
+       info.hour = nitz[3] != NET_INVALID_TIME ? nitz[3] : -1;
+       info.min = nitz[4] != NET_INVALID_TIME ? nitz[4] : -1;
+       info.sec = nitz[5] != NET_INVALID_TIME ? nitz[5] : -1;
+
+       /* Most significant bit set indicates negative offset. The
+        * second most significant bit is 'reserved'. The value is the
+        * offset from UTCin a count of 15min intervals, possibly
+        * including the current DST adjustment. */
+       info.utcoff = (nitz[6] & 0x3F) * 15 * 60;
+       if (nitz[6] & 0x80)
+               info.utcoff *= -1;
+
+       info.dst = nitz[7] != NET_INVALID_TIME ? nitz[7] : -1;
+
+       ofono_netreg_time_notify(netreg, &info);
+}
+
 static bool rssi_resp_cb(GIsiClient *client, const void *restrict data,
                                size_t len, uint16_t object, void *opaque)
 {
@@ -851,6 +889,7 @@ static gboolean isi_netreg_register(gpointer user)
        g_isi_subscribe(nd->client, NET_REG_STATUS_IND, reg_status_ind_cb,
                        netreg);
        g_isi_subscribe(nd->client, NET_RAT_IND, rat_ind_cb, netreg);
+       g_isi_subscribe(nd->client, NET_TIME_IND, time_ind_cb, netreg);
 
        /* Bootstrap current RAT setting */
        if (!g_isi_request_make(nd->client, rat, sizeof(rat),
index ec52321..77b4ec3 100644 (file)
@@ -30,6 +30,7 @@ extern "C" {
 #define NETWORK_TIMEOUT                5
 #define NETWORK_SCAN_TIMEOUT   180
 #define NETWORK_SET_TIMEOUT    240
+#define NET_INVALID_TIME       0x64
 
 enum net_message_id {
        NET_SET_REQ = 0x07,
@@ -37,6 +38,7 @@ enum net_message_id {
        NET_RSSI_GET_REQ = 0x0B,
        NET_RSSI_GET_RESP = 0x0C,
        NET_RSSI_IND = 0x1E,
+       NET_TIME_IND = 0x27,
        NET_RAT_IND = 0x35,
        NET_RAT_REQ = 0x36,
        NET_RAT_RESP = 0x37,
@@ -57,6 +59,7 @@ enum net_subblock {
        NET_GSM_REG_INFO = 0x09,
        NET_DETAILED_NETWORK_INFO = 0x0B,
        NET_GSM_OPERATOR_INFO = 0x0C,
+       NET_TIME_INFO = 0x10,
        NET_GSM_BAND_INFO = 0x11,
        NET_RAT_INFO = 0x2C,
        NET_AVAIL_NETWORK_INFO_COMMON = 0xE1,