daily pastebin goal
92%
SHARE
TWEET

Untitled

4javier Mar 27th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>
  3. #endif
  4.  
  5. #define _GNU_SOURCE
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9.  
  10. #include <glib.h>
  11.  
  12. #include <ofono/log.h>
  13. #include <ofono/modem.h>
  14. #include <ofono/netreg.h>
  15. #include <ofono/spn-table.h>
  16.  
  17. #include "common.h"
  18. #include "gril.h"
  19.  
  20. #include "grilreply.h"
  21. #include "grilrequest.h"
  22. #include "grilunsol.h"
  23. #include <ofono/netreg.h>
  24. static void ril_network_state_change(struct ril_msg *message,
  25.                             gpointer user_data)
  26. {
  27.     struct ofono_netreg *netreg = user_data;
  28.     struct netreg_data *nd = ofono_netreg_get_data(netreg);
  29.  
  30.     g_ril_print_unsol_no_args(nd->ril, message);
  31.  
  32.     ril_registration_status(netreg, NULL, NULL);
  33. }
  34.  
  35. static void ril_strength_notify(struct ril_msg *message, gpointer user_data)
  36. {
  37.     struct ofono_netreg *netreg = user_data;
  38.     struct netreg_data *nd = ofono_netreg_get_data(netreg);
  39.     int strength = g_ril_unsol_parse_signal_strength(nd->ril, message,
  40.                                 nd->tech);
  41.  
  42.     ofono_netreg_strength_notify(netreg, strength);
  43. }
  44.  
  45. static void ril_nitz_notify(struct ril_msg *message, gpointer user_data)
  46. {
  47.     struct ofono_netreg *netreg = user_data;
  48.     struct netreg_data *nd = ofono_netreg_get_data(netreg);
  49.     int year, mon, mday, hour, min, sec, dst, tzi, n_match;
  50.     char tzs, tz[4];
  51.     gchar *nitz;
  52.  
  53.     nitz = g_ril_unsol_parse_nitz(nd->ril, message);
  54.     if (nitz == NULL)
  55.         goto error;
  56.  
  57.     n_match = sscanf(nitz, "%u/%u/%u,%u:%u:%u%c%u,%u", &year, &mon,
  58.                 &mday, &hour, &min, &sec, &tzs, &tzi, &dst);
  59.     if (n_match != 9)
  60.         goto error;
  61.  
  62.     sprintf(tz, "%c%d", tzs, tzi);
  63.  
  64.     nd->time.utcoff = atoi(tz) * 15 * 60;
  65.     nd->time.dst = dst;
  66.     nd->time.sec = sec;
  67.     nd->time.min = min;
  68.     nd->time.hour = hour;
  69.     nd->time.mday = mday;
  70.     nd->time.mon = mon;
  71.     nd->time.year = 2000 + year;
  72.  
  73.     ofono_netreg_time_notify(netreg, &nd->time);
  74.  
  75.     g_free(nitz);
  76.  
  77.     return;
  78.  
  79. error:
  80.     ofono_error("%s: unable to notify ofono about NITZ (%s)",
  81.                         __func__, nitz ? nitz : "null");
  82.     g_free(nitz);
  83. }
  84.                            
  85. static gboolean ril_delayed_register(gpointer user_data)
  86. {
  87.     struct ofono_netreg *netreg = user_data;
  88.     struct netreg_data *nd = ofono_netreg_get_data(netreg);
  89.     ofono_netreg_register(netreg);
  90.  
  91.     /* Register for network state changes */
  92.     g_ril_register(nd->ril, RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
  93.             ril_network_state_change, netreg);
  94.  
  95.     /* Register for network time update reports */
  96.     g_ril_register(nd->ril, RIL_UNSOL_NITZ_TIME_RECEIVED,
  97.             ril_nitz_notify, netreg);
  98.  
  99.     /* Register for signal strength changes */
  100.     g_ril_register(nd->ril, RIL_UNSOL_SIGNAL_STRENGTH,
  101.             ril_strength_notify, netreg);
  102.            
  103.     g_ril_register(nd->ril, MTK2_RIL_UNSOL_RESPONSE_REGISTRATION_SUSPENDED,
  104.             mtk2_reg_suspended, netreg);
  105.  
  106.     /* This makes the timeout a single-shot */
  107.     return FALSE;
  108. }
  109.  
  110.  
  111. struct mtk2_ril_data {
  112.     GRil *ril;
  113.     enum ofono_ril_vendor vendor;
  114.     int sim_status_retries;
  115.     ofono_bool_t init_state;
  116.     ofono_bool_t ofono_online;
  117.     int radio_state;
  118.     struct ofono_sim *sim;
  119.     int rild_connect_retries;
  120.     GRilMsgIdToStrFunc request_id_to_string;
  121.     GRilMsgIdToStrFunc unsol_request_to_string;
  122.     ril_get_driver_type_func get_driver_type;
  123.     struct cb_data *set_online_cbd;
  124.     int suspend_id;
  125. }
  126.  
  127. static void mtk2_reg_suspended(struct ril_msg *message, gpointer user_data)
  128. {
  129.     struct ofono_modem *modem = user_data;
  130.     struct mtk2_ril_data *md = ofono_modem_get_data(modem);
  131.     struct parcel rilp;
  132.     int session_id;
  133.  
  134.     session_id = g_mtk2_unsol_parse_registration_suspended(md->ril, message);
  135.     if (session_id < 0) {
  136.         ofono_error("%s: parse error", __func__);
  137.         return;
  138.     }
  139.  
  140.     g_mtk2_request_resume_registration(md->ril, session_id, &rilp);
  141. }
  142.  
  143. void g_mtk2_request_resume_registration(GRil *gril, int session_id,
  144.                     struct parcel *rilp)
  145. {
  146.     parcel_init(rilp);
  147.     parcel_w_int32(rilp, 1);
  148.     parcel_w_int32(rilp, session_id);
  149.  
  150.     g_ril_append_print_buf(gril, "(%d)", session_id);
  151. }
  152.  
  153. int g_mtk2_unsol_parse_registration_suspended(GRil *gril,
  154.                         const struct ril_msg *message)
  155. {
  156.     struct parcel rilp;
  157.     int numint, session_id;
  158.  
  159.     g_ril_init_parcel(message, &rilp);
  160.  
  161.     numint = parcel_r_int32(&rilp);
  162.     if (numint != 1) {
  163.         ofono_error("%s Wrong format", __func__);
  164.         goto error;
  165.     }
  166.  
  167.     session_id = parcel_r_int32(&rilp);
  168.  
  169.     if (rilp.malformed) {
  170.         ofono_error("%s: malformed parcel", __func__);
  171.         goto error;
  172.     }
  173.  
  174.     g_ril_append_print_buf(gril, "{%d}", session_id);
  175.     g_ril_print_unsol(gril, message);
  176.  
  177.     return session_id;
  178.  
  179. error:
  180.     return -1;
  181.  
  182. }
RAW Paste Data
Top