1 /* //device/system/toolbox/resetradio.c
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
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
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
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.
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <cutils/sockets.h>
22
23 #define SOCKET_NAME_RIL_DEBUG "rild-debug" /* from ril.cpp */
24 #define SOCKET_NAME_RIL2_DEBUG "rild2-debug"
25
26 enum options {
27 RADIO_RESET,
28 RADIO_OFF,
29 UNSOL_NETWORK_STATE_CHANGE,
30 QXDM_ENABLE,
31 QXDM_DISABLE,
32 RADIO_ON,
33 SETUP_PDP,
34 DEACTIVATE_PDP,
35 DIAL_CALL,
36 ANSWER_CALL,
37 END_CALL,
38 };
39
40
print_usage()41 static void print_usage() {
42 perror("Usage: radiooptions [option] [extra_socket_args]\n\
43 0 - RADIO_RESET, \n\
44 1 - RADIO_OFF, \n\
45 2 - UNSOL_NETWORK_STATE_CHANGE, \n\
46 3 - QXDM_ENABLE, \n\
47 4 - QXDM_DISABLE, \n\
48 5 - RADIO_ON, \n\
49 6 apn- SETUP_PDP apn, \n\
50 7 - DEACTIVE_PDP, \n\
51 8 number - DIAL_CALL number, \n\
52 9 - ANSWER_CALL, \n\
53 10 - END_CALL \n\
54 The argument before the last one must be SIM slot \n\
55 0 - SIM1, \n\
56 1 - SIM2, \n\
57 2 - SIM3, \n\
58 3 - SIM4, \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");
62 }
63
error_check(int argc,char * argv[])64 static int error_check(int argc, char * argv[]) {
65 if (argc < 2) {
66 return -1;
67 }
68 const int option = atoi(argv[1]);
69 if (option < 0 || option > 10) {
70 return 0;
71 } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 5) {
72 return 0;
73 } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 4) {
74 return 0;
75 }
76 return -1;
77 }
78
get_number_args(char * argv[])79 static int get_number_args(char *argv[]) {
80 const int option = atoi(argv[1]);
81 if (option != DIAL_CALL && option != SETUP_PDP) {
82 return 3;
83 } else {
84 return 4;
85 }
86 }
87
main(int argc,char * argv[])88 int main(int argc, char *argv[])
89 {
90 int fd;
91 int num_socket_args = 0;
92 int i = 0;
93 int modem_socket_type = 0;
94 int sim_id = 0;
95 char socket_name[20];
96
97 if(error_check(argc, argv)) {
98 print_usage();
99 exit(-1);
100 }
101
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);
110 }
111
112 fd = socket_local_client(socket_name,
113 ANDROID_SOCKET_NAMESPACE_RESERVED,
114 SOCK_STREAM);
115 if (fd < 0) {
116 perror ("opening radio debug socket");
117 exit(-1);
118 }
119
120
121 /* It is not necessacry to pass the argument "modem-socket style" to rild */
122 num_socket_args--;
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");
126 close(fd);
127 exit(-1);
128 }
129
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");
136 close(fd);
137 exit(-1);
138 }
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");
142 close(fd);
143 exit(-1);
144 }
145 }
146
147 close(fd);
148 return 0;
149 }
150