2 * This file is part of Samsung-RIL.
4 * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
5 * Copyright (C) 2011-2012 Paul Kocialkowski <contact@paulk.fr>
7 * Samsung-RIL is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * Samsung-RIL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Samsung-RIL. If not, see <http://www.gnu.org/licenses/>.
22 #define LOG_TAG "RIL-NET"
23 #include <utils/Log.h>
25 #include "samsung-ril.h"
28 #include <plmn_list.h>
30 unsigned char ipc2ril_reg_state(unsigned char reg_state)
33 case IPC_NET_REGISTRATION_STATE_NONE:
35 case IPC_NET_REGISTRATION_STATE_HOME:
37 case IPC_NET_REGISTRATION_STATE_SEARCHING:
39 case IPC_NET_REGISTRATION_STATE_EMERGENCY:
41 case IPC_NET_REGISTRATION_STATE_ROAMING:
43 case IPC_NET_REGISTRATION_STATE_UNKNOWN:
46 LOGE("%s: invalid reg_state: %d", __func__, reg_state);
51 unsigned char ipc2ril_act(unsigned char act)
54 case IPC_NET_ACCESS_TECHNOLOGY_GPRS:
56 case IPC_NET_ACCESS_TECHNOLOGY_EDGE:
58 case IPC_NET_ACCESS_TECHNOLOGY_UMTS:
60 case IPC_NET_ACCESS_TECHNOLOGY_GSM:
61 case IPC_NET_ACCESS_TECHNOLOGY_GSM2:
67 unsigned char ipc2ril_gprs_act(unsigned char act)
70 case IPC_NET_ACCESS_TECHNOLOGY_GPRS:
72 case IPC_NET_ACCESS_TECHNOLOGY_EDGE:
74 case IPC_NET_ACCESS_TECHNOLOGY_UMTS:
76 case IPC_NET_ACCESS_TECHNOLOGY_GSM:
77 case IPC_NET_ACCESS_TECHNOLOGY_GSM2:
83 int ipc2ril_mode_sel(unsigned char mode)
87 return 7; // auto mode
88 case IPC_NET_MODE_SEL_GSM_UMTS:
90 case IPC_NET_MODE_SEL_GSM_ONLY:
92 case IPC_NET_MODE_SEL_UMTS_ONLY:
99 unsigned char ril2ipc_mode_sel(int mode)
103 return IPC_NET_MODE_SEL_GSM_ONLY;
104 case 2: // WCDMA only
105 return IPC_NET_MODE_SEL_UMTS_ONLY;
107 default: // GSM/WCDMA + the rest
108 return IPC_NET_MODE_SEL_GSM_UMTS;
112 int ipc2ril_plmn_sel(unsigned char mode)
115 case IPC_NET_PLMN_SEL_MANUAL:
117 case IPC_NET_PLMN_SEL_AUTO:
124 unsigned char ril2ipc_plmn_sel(int mode)
128 return IPC_NET_PLMN_SEL_AUTO;
130 return IPC_NET_PLMN_SEL_MANUAL;
136 void ipc2ril_reg_state_resp(struct ipc_net_regist_response *netinfo, char *response[15])
138 unsigned char reg_state;
141 if (netinfo == NULL || response == NULL)
144 reg_state = ipc2ril_reg_state(netinfo->reg_state);
145 act = ipc2ril_act(netinfo->act);
147 memset(response, 0, sizeof(response));
149 asprintf(&response[0], "%d", reg_state);
150 asprintf(&response[1], "%x", netinfo->lac);
151 asprintf(&response[2], "%x", netinfo->cid);
152 asprintf(&response[3], "%d", act);
155 void ipc2ril_gprs_reg_state_resp(struct ipc_net_regist_response *netinfo, char *response[4])
157 unsigned char reg_state;
160 if (netinfo == NULL || response == NULL)
163 reg_state = ipc2ril_reg_state(netinfo->reg_state);
164 act = ipc2ril_gprs_act(netinfo->act);
166 memset(response, 0, sizeof(response));
168 asprintf(&response[0], "%d", reg_state);
169 asprintf(&response[1], "%x", netinfo->lac);
170 asprintf(&response[2], "%x", netinfo->cid);
171 asprintf(&response[3], "%d", act);
175 * Set all the tokens to data waiting.
176 * For instance when only operator is updated by modem NOTI, we don't need
177 * to ask the modem new NET Regist and GPRS Net Regist states so act like we got
178 * these from modem NOTI too so we don't have to make the requests
180 void ril_tokens_net_set_data_waiting(void)
182 ril_data.tokens.registration_state = RIL_TOKEN_DATA_WAITING;
183 ril_data.tokens.gprs_registration_state = RIL_TOKEN_DATA_WAITING;
184 ril_data.tokens.operator = RIL_TOKEN_DATA_WAITING;
188 * Returns 1 if unsol data is waiting, 0 if not
190 int ril_tokens_net_get_data_waiting(void)
192 return ril_data.tokens.registration_state == RIL_TOKEN_DATA_WAITING || ril_data.tokens.gprs_registration_state == RIL_TOKEN_DATA_WAITING || ril_data.tokens.operator == RIL_TOKEN_DATA_WAITING;
195 void ril_tokens_net_state_dump(void)
197 LOGD("ril_tokens_net_state_dump:\n\
198 \tril_data.tokens.registration_state = %p\n\
199 \tril_data.tokens.gprs_registration_state = %p\n\
200 \tril_data.tokens.operator = %p\n", ril_data.tokens.registration_state, ril_data.tokens.gprs_registration_state, ril_data.tokens.operator);
203 void ril_plmn_split(char *plmn_data, char **plmn, unsigned int *mcc, unsigned int *mnc)
208 memset(plmn_t, 0, sizeof(plmn_t));
209 memcpy(plmn_t, plmn_data, 6);
211 if (plmn_t[5] == '#')
215 *plmn = malloc(sizeof(plmn_t));
216 memcpy(*plmn, plmn_t, sizeof(plmn_t));
219 if (mcc == NULL || mnc == NULL)
222 sscanf(plmn_t, "%3u%2u", mcc, mnc);
225 void ril_plmn_string(char *plmn_data, char *response[3])
227 unsigned int mcc, mnc;
233 if (plmn_data == NULL || response == NULL)
236 ril_plmn_split(plmn_data, &plmn, &mcc, &mnc);
238 asprintf(&response[2], "%s", plmn);
243 plmn_entries = sizeof(plmn_list) / sizeof(struct plmn_list_entry);
245 LOGD("Found %d plmn records", plmn_entries);
247 for (i=0 ; i < plmn_entries ; i++) {
248 if (plmn_list[i].mcc == mcc && plmn_list[i].mnc == mnc) {
249 asprintf(&response[0], "%s", plmn_list[i].operator_long);
250 asprintf(&response[1], "%s", plmn_list[i].operator_short);
260 * How to handle NET unsol data from modem:
261 * 1- Rx UNSOL (NOTI) data from modem
262 * 2- copy data in a sized variable stored in radio
263 * 3- make sure no SOL request is going on for this token
264 * 4- copy data to radio structure
265 * 5- if no UNSOL data is already waiting for a token, tell RILJ NETWORK_STATE_CHANGED
266 * 6- set all the net tokens to RIL_TOKEN_DATA_WAITING
267 * 7- RILJ will ask for OPERATOR, GPRS_REG_STATE and REG_STATE
269 * 8- if token is RIL_TOKEN_DATA_WAITING it's SOL request for modem UNSOL data
270 * 9- send back modem data and tell E_SUCCESS to RILJ request
271 * 10- set token to 0x00
273 * How to handle NET sol requests from RILJ:
274 * 1- if token is 0x00 it's UNSOL RILJ request for modem data
275 * 2- put RIL_Token in token
276 * 3- request data to the modem
277 * 4- Rx SOL (RESP) data from modem
278 * 5- copy data to radio structure
279 * 6- send back data to RILJ with token from modem message
280 * 7- if token != RIL_TOKEN_DATA_WAITING, reset token to 0x00
282 * What if both are appening at the same time?
283 * 1- RILJ requests modem data (UNSOL)
284 * 2- token is 0x00 so send request to modem
285 * 3- UNSOL data arrives from modem
286 * 4- set all tokens to RIL_TOKEN_DATA_WAITING
287 * 5- store data, tell RILJ NETWORK_STATE_CHANGED
288 * 6- Rx requested data from modem
289 * 7- copy data to radio structure
290 * 8- token mismatch (is now RIL_TOKEN_DATA_WAITING)
291 * 9- send back data to RIL with token from IPC message
292 * 10- don't reset token to 0x00
293 * 11- RILJ does SOL request for modem data (we know it's SOL because we didn't reset token)
294 * 12- send back last data we have (from UNSOL RILJ request here)
297 void ril_request_operator(RIL_Token t)
302 // IPC_NET_REGISTRATION_STATE_ROAMING is the biggest valid value
303 if (ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_NONE ||
304 ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_SEARCHING ||
305 ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_UNKNOWN ||
306 ril_data.state.netinfo.reg_state > IPC_NET_REGISTRATION_STATE_ROAMING) {
307 ril_request_complete(t, RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW, NULL, 0);
309 ril_data.tokens.operator = (RIL_Token) 0x00;
313 if (ril_data.tokens.operator == RIL_TOKEN_DATA_WAITING) {
314 LOGD("Got RILJ request for UNSOL data");
316 /* Send back the data we got UNSOL */
317 ril_plmn_string(ril_data.state.plmndata.plmn, response);
319 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
321 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
322 if (response[i] != NULL)
326 ril_data.tokens.operator = (RIL_Token) 0x00;
327 } else if (ril_data.tokens.operator == (RIL_Token) 0x00) {
328 LOGD("Got RILJ request for SOL data");
329 /* Request data to the modem */
330 ril_data.tokens.operator = t;
332 ipc_fmt_send_get(IPC_NET_CURRENT_PLMN, ril_request_get_id(t));
334 LOGE("Another request is going on, returning UNSOL data");
336 /* Send back the data we got UNSOL */
337 ril_plmn_string(ril_data.state.plmndata.plmn, response);
339 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
341 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
342 if (response[i] != NULL)
347 ril_tokens_net_state_dump();
350 void ipc_net_current_plmn(struct ipc_message_info *info)
352 struct ipc_net_current_plmn_response *plmndata;
358 if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_net_current_plmn_response))
361 plmndata = (struct ipc_net_current_plmn_response *) info->data;
362 t = ril_request_get_token(info->aseq);
364 switch (info->type) {
366 LOGD("Got UNSOL Operator message");
368 // IPC_NET_REGISTRATION_STATE_ROAMING is the biggest valid value
369 if (ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_NONE ||
370 ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_SEARCHING ||
371 ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_UNKNOWN ||
372 ril_data.state.netinfo.reg_state > IPC_NET_REGISTRATION_STATE_ROAMING) {
373 /* Better keeping it up to date */
374 memcpy(&(ril_data.state.plmndata), plmndata, sizeof(struct ipc_net_current_plmn_response));
378 if (ril_data.tokens.operator != (RIL_Token) 0x00 && ril_data.tokens.operator != RIL_TOKEN_DATA_WAITING) {
379 LOGE("Another Operator Req is in progress, skipping");
383 memcpy(&(ril_data.state.plmndata), plmndata, sizeof(struct ipc_net_current_plmn_response));
385 /* we already told RILJ to get the new data but it wasn't done yet */
386 if (ril_tokens_net_get_data_waiting() && ril_data.tokens.operator == RIL_TOKEN_DATA_WAITING) {
387 LOGD("Updating Operator data in background");
389 ril_tokens_net_set_data_waiting();
391 ril_request_unsolicited(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0);
393 ril_request_unsolicited(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED, NULL, 0);
399 LOGD("Got SOL Operator message");
401 // IPC_NET_REGISTRATION_STATE_ROAMING is the biggest valid value
402 if (ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_NONE ||
403 ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_SEARCHING ||
404 ril_data.state.netinfo.reg_state == IPC_NET_REGISTRATION_STATE_UNKNOWN ||
405 ril_data.state.netinfo.reg_state > IPC_NET_REGISTRATION_STATE_ROAMING) {
406 /* Better keeping it up to date */
407 memcpy(&(ril_data.state.plmndata), plmndata, sizeof(struct ipc_net_current_plmn_response));
409 ril_request_complete(t, RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW, NULL, 0);
411 if (ril_data.tokens.operator != RIL_TOKEN_DATA_WAITING)
412 ril_data.tokens.operator = (RIL_Token) 0x00;
415 if (ril_data.tokens.operator != t)
416 LOGE("Operator tokens mismatch");
418 /* Better keeping it up to date */
419 memcpy(&(ril_data.state.plmndata), plmndata, sizeof(struct ipc_net_current_plmn_response));
421 ril_plmn_string(plmndata->plmn, response);
423 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
425 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
426 if (response[i] != NULL)
430 if (ril_data.tokens.operator != RIL_TOKEN_DATA_WAITING)
431 ril_data.tokens.operator = (RIL_Token) 0x00;
435 LOGE("%s: unhandled ipc method: %d", __func__, info->type);
439 ril_tokens_net_state_dump();
445 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
449 void ril_request_voice_registration_state(RIL_Token t)
451 void ril_request_registration_state(RIL_Token t)
454 struct ipc_net_regist_get regist_req;
458 if (ril_data.tokens.registration_state == RIL_TOKEN_DATA_WAITING) {
459 LOGD("Got RILJ request for UNSOL data");
461 /* Send back the data we got UNSOL */
462 ipc2ril_reg_state_resp(&(ril_data.state.netinfo), response);
464 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
466 for (i = 0; i < (int) (sizeof(response) / sizeof(char *)) ; i++) {
467 if (response[i] != NULL)
471 ril_data.tokens.registration_state = (RIL_Token) 0x00;
472 } else if (ril_data.tokens.registration_state == (RIL_Token) 0x00) {
473 LOGD("Got RILJ request for SOL data");
474 /* Request data to the modem */
475 ril_data.tokens.registration_state = t;
477 ipc_net_regist_get_setup(®ist_req, IPC_NET_SERVICE_DOMAIN_GSM);
478 ipc_fmt_send(IPC_NET_REGIST, IPC_TYPE_GET, (void *)®ist_req, sizeof(struct ipc_net_regist_get), ril_request_get_id(t));
480 LOGE("Another request is going on, returning UNSOL data");
482 /* Send back the data we got UNSOL */
483 ipc2ril_reg_state_resp(&(ril_data.state.netinfo), response);
485 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
487 for (i = 0; i < (int) (sizeof(response) / sizeof(char *)) ; i++) {
488 if (response[i] != NULL)
493 ril_tokens_net_state_dump();
497 void ril_request_data_registration_state(RIL_Token t)
499 void ril_request_gprs_registration_state(RIL_Token t)
502 struct ipc_net_regist_get regist_req;
506 if (ril_data.tokens.gprs_registration_state == RIL_TOKEN_DATA_WAITING) {
507 LOGD("Got RILJ request for UNSOL data");
509 /* Send back the data we got UNSOL */
510 ipc2ril_gprs_reg_state_resp(&(ril_data.state.gprs_netinfo), response);
512 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
514 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
515 if (response[i] != NULL)
519 ril_data.tokens.gprs_registration_state = (RIL_Token) 0x00;
520 } else if (ril_data.tokens.gprs_registration_state == (RIL_Token) 0x00) {
521 LOGD("Got RILJ request for SOL data");
523 /* Request data to the modem */
524 ril_data.tokens.gprs_registration_state = t;
526 ipc_net_regist_get_setup(®ist_req, IPC_NET_SERVICE_DOMAIN_GPRS);
527 ipc_fmt_send(IPC_NET_REGIST, IPC_TYPE_GET, (void *)®ist_req, sizeof(struct ipc_net_regist_get), ril_request_get_id(t));
529 LOGE("Another request is going on, returning UNSOL data");
531 /* Send back the data we got UNSOL */
532 ipc2ril_gprs_reg_state_resp(&(ril_data.state.gprs_netinfo), response);
534 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
536 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
537 if (response[i] != NULL)
542 ril_tokens_net_state_dump();
545 void ipc_net_regist_unsol(struct ipc_message_info *info)
547 struct ipc_net_regist_response *netinfo;
549 if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_net_regist_response))
552 netinfo = (struct ipc_net_regist_response *) info->data;
554 LOGD("Got UNSOL NetRegist message");
556 switch(netinfo->domain) {
557 case IPC_NET_SERVICE_DOMAIN_GSM:
558 if (ril_data.tokens.registration_state != (RIL_Token) 0 && ril_data.tokens.registration_state != RIL_TOKEN_DATA_WAITING) {
559 LOGE("Another NetRegist Req is in progress, skipping");
563 memcpy(&(ril_data.state.netinfo), netinfo, sizeof(struct ipc_net_regist_response));
565 /* we already told RILJ to get the new data but it wasn't done yet */
566 if (ril_tokens_net_get_data_waiting() && ril_data.tokens.registration_state == RIL_TOKEN_DATA_WAITING) {
567 LOGD("Updating NetRegist data in background");
569 ril_tokens_net_set_data_waiting();
571 ril_request_unsolicited(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0);
573 ril_request_unsolicited(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED, NULL, 0);
578 case IPC_NET_SERVICE_DOMAIN_GPRS:
579 if (ril_data.tokens.gprs_registration_state != (RIL_Token) 0 && ril_data.tokens.gprs_registration_state != RIL_TOKEN_DATA_WAITING) {
580 LOGE("Another GPRS NetRegist Req is in progress, skipping");
584 memcpy(&(ril_data.state.gprs_netinfo), netinfo, sizeof(struct ipc_net_regist_response));
586 /* we already told RILJ to get the new data but it wasn't done yet */
587 if (ril_tokens_net_get_data_waiting() && ril_data.tokens.gprs_registration_state == RIL_TOKEN_DATA_WAITING) {
588 LOGD("Updating GPRSNetRegist data in background");
590 ril_tokens_net_set_data_waiting();
592 ril_request_unsolicited(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0);
594 ril_request_unsolicited(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED, NULL, 0);
599 LOGE("%s: unhandled service domain: %d", __func__, netinfo->domain);
603 ril_tokens_net_state_dump();
609 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
612 void ipc_net_regist_sol(struct ipc_message_info *info)
614 struct ipc_net_regist_response *netinfo;
620 if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_net_regist_response))
623 netinfo = (struct ipc_net_regist_response *) info->data;
624 t = ril_request_get_token(info->aseq);
626 LOGD("Got SOL NetRegist message");
628 switch(netinfo->domain) {
629 case IPC_NET_SERVICE_DOMAIN_GSM:
630 if (ril_data.tokens.registration_state != t)
631 LOGE("Registration state tokens mismatch");
633 /* Better keeping it up to date */
634 memcpy(&(ril_data.state.netinfo), netinfo, sizeof(struct ipc_net_regist_response));
636 ipc2ril_reg_state_resp(netinfo, response);
638 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
640 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
641 if (response[i] != NULL)
645 if (ril_data.tokens.registration_state != RIL_TOKEN_DATA_WAITING)
646 ril_data.tokens.registration_state = (RIL_Token) 0x00;
648 case IPC_NET_SERVICE_DOMAIN_GPRS:
649 if (ril_data.tokens.gprs_registration_state != t)
650 LOGE("GPRS registration state tokens mismatch");
652 /* Better keeping it up to date */
653 memcpy(&(ril_data.state.gprs_netinfo), netinfo, sizeof(struct ipc_net_regist_response));
655 ipc2ril_gprs_reg_state_resp(netinfo, response);
657 ril_request_complete(t, RIL_E_SUCCESS, response, sizeof(response));
659 for (i = 0; i < sizeof(response) / sizeof(char *) ; i++) {
660 if (response[i] != NULL)
663 if (ril_data.tokens.registration_state != RIL_TOKEN_DATA_WAITING)
664 ril_data.tokens.gprs_registration_state = (RIL_Token) 0x00;
667 LOGE("%s: unhandled service domain: %d", __func__, netinfo->domain);
671 ril_tokens_net_state_dump();
677 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
680 void ipc_net_regist(struct ipc_message_info *info)
685 /* Don't consider this if modem isn't in normal power mode. */
686 if (ril_data.state.power_state != IPC_PWR_PHONE_STATE_NORMAL)
691 ipc_net_regist_unsol(info);
694 ipc_net_regist_sol(info);
697 LOGE("%s: unhandled ipc method: %d", __func__, info->type);
703 void ril_request_query_available_networks(RIL_Token t)
705 ipc_fmt_send_get(IPC_NET_PLMN_LIST, ril_request_get_id(t));
708 void ipc_net_plmn_list(struct ipc_message_info *info)
710 struct ipc_net_plmn_entries *entries_info;
711 struct ipc_net_plmn_entry *entries;
720 if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_net_plmn_entries))
723 entries_info = (struct ipc_net_plmn_entries *) info->data;
724 entries = (struct ipc_net_plmn_entry *) (info->data + sizeof(struct ipc_net_plmn_entries));
726 LOGD("Listed %d PLMNs\n", entries_info->num);
728 length = sizeof(char *) * 4 * entries_info->num;
729 response = (char **) calloc(1, length);
732 for (i=0 ; i < entries_info->num ; i++) {
733 // Assumed type for 'emergency only' PLMNs
734 if (entries[i].type == 0x01)
738 ril_plmn_string(entries[i].plmn, &response[index]);
740 index = count * 4 + 3;
741 switch (entries[i].status) {
742 case IPC_NET_PLMN_STATUS_AVAILABLE:
743 response[index] = strdup("available");
745 case IPC_NET_PLMN_STATUS_CURRENT:
746 response[index] = strdup("current");
748 case IPC_NET_PLMN_STATUS_FORBIDDEN:
749 response[index] = strdup("forbidden");
752 response[index] = strdup("unknown");
759 length = sizeof(char *) * 4 * count;
760 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, response, length);
762 for (i=0 ; i < entries_info->num ; i++)
763 if (response[i] != NULL)
772 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
775 void ril_request_get_preferred_network_type(RIL_Token t)
777 ipc_fmt_send_get(IPC_NET_MODE_SEL, ril_request_get_id(t));
780 void ril_request_set_preferred_network_type(RIL_Token t, void *data, size_t length)
783 struct ipc_net_mode_sel mode_sel;
785 if (data == NULL || length < (int) sizeof(int))
788 ril_mode = *((int *) data);
790 mode_sel.mode_sel = ril2ipc_mode_sel(ril_mode);
792 ipc_gen_phone_res_expect_to_complete(ril_request_get_id(t), IPC_NET_MODE_SEL);
794 ipc_fmt_send(IPC_NET_MODE_SEL, IPC_TYPE_SET, (unsigned char *) &mode_sel, sizeof(mode_sel), ril_request_get_id(t));
799 ril_request_complete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
802 void ipc_net_mode_sel(struct ipc_message_info *info)
804 struct ipc_net_mode_sel *mode_sel;
807 if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_net_mode_sel))
810 mode_sel = (struct ipc_net_mode_sel *) info->data;
811 ril_mode = ipc2ril_mode_sel(mode_sel->mode_sel);
813 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, &ril_mode, sizeof(ril_mode));
819 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
822 void ril_request_query_network_selection_mode(RIL_Token t)
824 ipc_fmt_send_get(IPC_NET_PLMN_SEL, ril_request_get_id(t));
827 void ipc_net_plmn_sel(struct ipc_message_info *info)
829 struct ipc_net_plmn_sel_get *plmn_sel;
832 if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_net_plmn_sel_get))
835 plmn_sel = (struct ipc_net_plmn_sel_get *) info->data;
836 ril_mode = ipc2ril_plmn_sel(plmn_sel->plmn_sel);
838 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, &ril_mode, sizeof(ril_mode));
844 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
847 void ipc_net_plmn_sel_complete(struct ipc_message_info *info)
849 struct ipc_gen_phone_res *phone_res;
852 phone_res = (struct ipc_gen_phone_res *) info->data;
854 rc = ipc_gen_phone_res_check(phone_res);
856 if ((phone_res->code & 0x00ff) == 0x6f) {
857 LOGE("Not authorized to register to this network!");
858 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_ILLEGAL_SIM_OR_ME, NULL, 0);
860 LOGE("There was an error during operator selection!");
861 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
866 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, NULL, 0);
869 void ril_request_set_network_selection_automatic(RIL_Token t)
871 struct ipc_net_plmn_sel_set plmn_sel;
873 ipc_net_plmn_sel_set_setup(&plmn_sel, IPC_NET_PLMN_SEL_AUTO, NULL, IPC_NET_ACCESS_TECHNOLOGY_UNKNOWN);
875 ipc_gen_phone_res_expect_to_func(ril_request_get_id(t), IPC_NET_PLMN_SEL, ipc_net_plmn_sel_complete);
877 ipc_fmt_send(IPC_NET_PLMN_SEL, IPC_TYPE_SET, (unsigned char *) &plmn_sel, sizeof(plmn_sel), ril_request_get_id(t));
880 void ril_request_set_network_selection_manual(RIL_Token t, void *data, size_t length)
882 struct ipc_net_plmn_sel_set plmn_sel;
884 if (data == NULL || length < (int) sizeof(char *))
887 // FIXME: We always assume UMTS capability
888 ipc_net_plmn_sel_set_setup(&plmn_sel, IPC_NET_PLMN_SEL_MANUAL, data, IPC_NET_ACCESS_TECHNOLOGY_UMTS);
890 ipc_gen_phone_res_expect_to_func(ril_request_get_id(t), IPC_NET_PLMN_SEL, ipc_net_plmn_sel_complete);
892 ipc_fmt_send(IPC_NET_PLMN_SEL, IPC_TYPE_SET, (unsigned char *) &plmn_sel, sizeof(plmn_sel), ril_request_get_id(t));