Add ril v2 OOS

Change-Id: I70044a12d33177379d8635ee870d5ce2b2826ab7
diff --git a/mbtk/mbtk_rild_v2/src/ril_net.c b/mbtk/mbtk_rild_v2/src/ril_net.c
index 837f1cc..fc381f4 100755
--- a/mbtk/mbtk_rild_v2/src/ril_net.c
+++ b/mbtk/mbtk_rild_v2/src/ril_net.c
@@ -1187,6 +1187,137 @@
     return err;
 }
 
+/*
+AT+OOSPP=1
+or
+AT+OOSPP=0
+or
+AT+OOSPP=1,20,30,40 //AtOospp()
+ param1£ºmode
+ param2£ºoosPhasePeriod[0] //5 times, 5s by default;
+ param3£ºoosPhasePeriod[1] //5 times, 10s by default;
+ param4£ºoosPhasePeriod[2] //unlimited, 20s by default;
+
+
+BTW
+1, Èç¹ûÖ»ÊäÈëmode=1£¬ÆäÓà²ÎÊý²»ÉèÖã¬Ï൱ÓÚÕâ¸ö¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊÇÕâ¸ö¹¦ÄܵÄĬÈÏÖµ¡£
+2, Èç¹ûµ±mode=1¼ÓÉÏÆäÓàÉèÖòÎÊýºó£¬¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊDZ¾´ÎÉèÖõÄÖµ£»
+3£¬Èç¹ûÔÙÉèÖÃmode=0£¬Ï൱ÓÚÕâ¸ö¹¦Äܹرգ¬ÊÇ×߯½Ì¨×Ô¼ºÁíÒ»Ì×µÄËÑÍøÉèÖá£
+ƽ̨±¾ÉíÊÇÓÐÒ»Ì×¼ä¸ôËÑÍø£¬Ò²ÓÐÀúʷƵµãÓÅÏÈ´¦ÀíµÄÂß¼­£¨²»ÐèÒªÎÒÃǽøÐд¦Àí£©£¬
+Ìṩ¸øÎÒÃǵÄAT+OOSPPÖ¸ÁîÊÇÈÃÎÒÃÇ¿ÉÒÔ×Ô¶¨ÒåËÑÍø¼ä¸ô
+*/
+static int req_oos_set(ATPortType_enum port, const mbtk_ril_oos_info_t* oos_info, int *cme_err)
+{
+    ATResponse *response = NULL;
+    char cmd[100] = {0};
+    int err = 0;
+
+    if ((oos_info->state == 1 && oos_info->oosPhase[0] == 0 && oos_info->oosPhase[1] == 0 && oos_info->oosPhase[2] == 0) \
+        || oos_info->state == 0)
+    {
+        sprintf(cmd, "AT+OOSPP=%d", oos_info->state);//Ö»ÓÐÒ»¸öÖµ0/1
+    }
+    else
+    {
+        if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] != 0))
+        {
+            sprintf(cmd, "AT+OOSPP=%d,%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1], oos_info->oosPhase[2]);
+        }
+        else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] == 0))
+        {
+            sprintf(cmd, "AT+OOSPP=%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1]);
+        }
+        else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] == 0) && (oos_info->oosPhase[2] == 0))
+        {
+            sprintf(cmd, "AT+OOSPP=%d,%d", oos_info->state, oos_info->oosPhase[0]);
+        }
+        else
+        {
+            LOGE("AT+OOSPP SET ERR");
+            goto exit;
+        }
+    }
+
+    LOGI("Set the oos command is = [%s]\n", cmd);
+    err = at_send_command(port, cmd, &response);
+    if (err < 0 || response->success == 0){
+        *cme_err = at_get_cme_error(response);
+        goto exit;
+    }
+
+exit:
+    at_response_free(response);
+    return err;
+}
+
+/*
+AT+OOSPP?
+¿ª(ĬÈÏÖµ)£º
++OOSPP:5,10,20
+¹Ø£º
++OOSPP:0
+*/
+static int req_oos_get(ATPortType_enum port, mbtk_ril_oos_info_t *oos_info, int *cme_err)
+{
+    ATResponse *response = NULL;
+
+    int err = at_send_command_singleline(port, "AT+OOSPP?", "+OOSPP:", &response);
+
+    if (err < 0 || response->success == 0 || !response->p_intermediates){
+        *cme_err = at_get_cme_error(response);
+        goto exit;
+    }
+
+    char *line = response->p_intermediates->line;
+
+    char *tmp_str = NULL;
+    err = at_tok_start(&line);//+OOSPP:10,15,20,¹ýÂË+OOSPP:
+    if (err < 0)
+    {
+        goto exit;
+    }
+
+    //LOG("req_oos_get =[%s]",line);
+
+    err = at_tok_nextstr(&line, &tmp_str);
+    if (err < 0)
+    {
+        goto exit;
+    }
+
+    int mode = atoi(tmp_str);
+    if (mode == 0)//¹Ø±Õ״̬
+    {
+        oos_info->state = mode;
+    }
+    else//¿ª×´Ì¬
+    {
+        oos_info->state = 1;
+        //LOG("tmp_str =[%s]",tmp_str);
+        oos_info->oosPhase[0] = atoi(tmp_str);
+
+        err = at_tok_nextstr(&line, &tmp_str);
+        if (err < 0)
+        {
+            goto exit;
+        }
+        //LOG("tmp_str =[%s]",tmp_str);
+        oos_info->oosPhase[1] = atoi(tmp_str);
+
+        err = at_tok_nextstr(&line, &tmp_str);
+        if (err < 0)
+        {
+            goto exit;
+        }
+        //LOG("tmp_str =[%s]",tmp_str);
+        oos_info->oosPhase[2] = atoi(tmp_str);
+    }
+
+exit:
+    at_response_free(response);
+    return err;
+}
+
 //void net_list_free(void *data);
 // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
 // Otherwise, do not call pack_error_send().
@@ -1410,6 +1541,45 @@
             }
             break;
         }
+        case RIL_MSG_ID_NET_OOS:
+        {
+            if(pack->data_len == 0 || pack->data == NULL)   // Get net oos.
+            {
+                mbtk_ril_oos_info_t oos_info;
+                memset(&oos_info, 0, sizeof(mbtk_ril_oos_info_t));
+                if(req_oos_get(cli_info->port, &oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                {
+                    if(cme_err != MBTK_RIL_ERR_CME_NON) {
+                        err = MBTK_RIL_ERR_CME + cme_err;
+                    } else {
+                        err = MBTK_RIL_ERR_UNKNOWN;
+                    }
+                    LOG("Get net oos fail.");
+                }
+                else
+                {
+                    LOG("req_oos_get() success,cell number: %d", oos_info.state);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &oos_info, sizeof(mbtk_ril_oos_info_t));
+                }
+            }
+            else     // Set net oos.
+            {
+                mbtk_ril_oos_info_t *oos_info = (mbtk_ril_oos_info_t*)(pack->data);
+                if(req_oos_set(cli_info->port, oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                {
+                    if(cme_err != MBTK_RIL_ERR_CME_NON) {
+                        err = MBTK_RIL_ERR_CME + cme_err;
+                    } else {
+                        err = MBTK_RIL_ERR_UNKNOWN;
+                    }
+                }
+                else
+                {
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                }
+            }
+            break;
+        }
         default:
         {
             err = MBTK_RIL_ERR_REQ_UNKNOWN;