1 /* //device/system/toolbox/resetradio.c
3 ** Copyright 2006, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
21 #include <cutils/sockets.h>
23 #define SOCKET_NAME_RIL_DEBUG "rild-debug" /* from ril.cpp */
24 #define SOCKET_NAME_RIL2_DEBUG "rild2-debug"
29 UNSOL_NETWORK_STATE_CHANGE,
41 static void print_usage() {
42 perror("Usage: radiooptions [option] [extra_socket_args]\n\
45 2 - UNSOL_NETWORK_STATE_CHANGE, \n\
49 6 apn- SETUP_PDP apn, \n\
51 8 number - DIAL_CALL number, \n\
54 The argument before the last one must be SIM slot \n\
59 The last argument must be modem-socket style \n\
60 0 - one modem for one debug-socket, \n\
61 1 - one modem for multiple debug socket \n");
64 static int error_check(int argc, char * argv[]) {
68 const int option = atoi(argv[1]);
69 if (option < 0 || option > 10) {
71 } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 5) {
73 } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 4) {
79 static int get_number_args(char *argv[]) {
80 const int option = atoi(argv[1]);
81 if (option != DIAL_CALL && option != SETUP_PDP) {
88 int main(int argc, char *argv[])
91 int num_socket_args = 0;
93 int modem_socket_type = 0;
97 if(error_check(argc, argv)) {
102 num_socket_args = get_number_args(argv);
103 modem_socket_type = atoi(argv[(num_socket_args-1)]);
104 sim_id = atoi(argv[(num_socket_args-2)]);
105 memset(socket_name, 0, sizeof(char)*20);
106 if (sim_id == 0 || modem_socket_type == 1) {
107 strncpy(socket_name, SOCKET_NAME_RIL_DEBUG, 19);
108 } else if (sim_id == 1) {
109 strncpy(socket_name, SOCKET_NAME_RIL2_DEBUG, 19);
112 fd = socket_local_client(socket_name,
113 ANDROID_SOCKET_NAMESPACE_RESERVED,
116 perror ("opening radio debug socket");
121 /* It is not necessacry to pass the argument "modem-socket style" to rild */
123 int ret = send(fd, (const void *)&num_socket_args, sizeof(int), 0);
124 if(ret != sizeof(int)) {
125 perror ("Socket write error when sending num args");
130 for (i = 0; i < num_socket_args; i++) {
131 // Send length of the arg, followed by the arg.
132 int len = strlen(argv[1 + i]);
133 ret = send(fd, &len, sizeof(int), 0);
134 if (ret != sizeof(int)) {
135 perror("Socket write Error: when sending arg length");
139 ret = send(fd, argv[1 + i], sizeof(char) * len, 0);
140 if (ret != len * sizeof(char)) {
141 perror ("Socket write Error: When sending arg");