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 */
28 UNSOL_NETWORK_STATE_CHANGE,
40 static void print_usage() {
41 perror("Usage: radiooptions [option] [extra_socket_args]\n\
44 2 - UNSOL_NETWORK_STATE_CHANGE, \n\
48 6 apn- SETUP_PDP apn, \n\
50 8 number - DIAL_CALL number, \n\
55 static int error_check(int argc, char * argv[]) {
59 const int option = atoi(argv[1]);
60 if (option < 0 || option > 10) {
62 } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 3) {
64 } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 2) {
70 static int get_number_args(char *argv[]) {
71 const int option = atoi(argv[1]);
72 if (option != DIAL_CALL && option != SETUP_PDP) {
79 int main(int argc, char *argv[])
82 int num_socket_args = 0;
84 if(error_check(argc, argv)) {
89 fd = socket_local_client(SOCKET_NAME_RIL_DEBUG,
90 ANDROID_SOCKET_NAMESPACE_RESERVED,
93 perror ("opening radio debug socket");
97 num_socket_args = get_number_args(argv);
98 int ret = send(fd, (const void *)&num_socket_args, sizeof(int), 0);
99 if(ret != sizeof(int)) {
100 perror ("Socket write error when sending num args");
105 for (i = 0; i < num_socket_args; i++) {
106 // Send length of the arg, followed by the arg.
107 int len = strlen(argv[1 + i]);
108 ret = send(fd, &len, sizeof(int), 0);
109 if (ret != sizeof(int)) {
110 perror("Socket write Error: when sending arg length");
114 ret = send(fd, argv[1 + i], sizeof(char) * len, 0);
115 if (ret != len * sizeof(char)) {
116 perror ("Socket write Error: When sending arg");