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 25 enum options { 26 RADIO_RESET, 27 RADIO_OFF, 28 UNSOL_NETWORK_STATE_CHANGE, 29 QXDM_ENABLE, 30 QXDM_DISABLE, 31 RADIO_ON, 32 SETUP_PDP, 33 DEACTIVATE_PDP, 34 DIAL_CALL, 35 ANSWER_CALL, 36 END_CALL, 37 }; 38 39 40 static void print_usage() { 41 perror("Usage: radiooptions [option] [extra_socket_args]\n\ 42 0 - RADIO_RESET, \n\ 43 1 - RADIO_OFF, \n\ 44 2 - UNSOL_NETWORK_STATE_CHANGE, \n\ 45 3 - QXDM_ENABLE, \n\ 46 4 - QXDM_DISABLE, \n\ 47 5 - RADIO_ON, \n\ 48 6 apn- SETUP_PDP apn, \n\ 49 7 - DEACTIVE_PDP, \n\ 50 8 number - DIAL_CALL number, \n\ 51 9 - ANSWER_CALL, \n\ 52 10 - END_CALL \n"); 53 } 54 55 static int error_check(int argc, char * argv[]) { 56 if (argc < 2) { 57 return -1; 58 } 59 const int option = atoi(argv[1]); 60 if (option < 0 || option > 10) { 61 return 0; 62 } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 3) { 63 return 0; 64 } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 2) { 65 return 0; 66 } 67 return -1; 68 } 69 70 static int get_number_args(char *argv[]) { 71 const int option = atoi(argv[1]); 72 if (option != DIAL_CALL && option != SETUP_PDP) { 73 return 1; 74 } else { 75 return 2; 76 } 77 } 78 79 int main(int argc, char *argv[]) 80 { 81 int fd; 82 int num_socket_args = 0; 83 int i = 0; 84 if(error_check(argc, argv)) { 85 print_usage(); 86 exit(-1); 87 } 88 89 fd = socket_local_client(SOCKET_NAME_RIL_DEBUG, 90 ANDROID_SOCKET_NAMESPACE_RESERVED, 91 SOCK_STREAM); 92 if (fd < 0) { 93 perror ("opening radio debug socket"); 94 exit(-1); 95 } 96 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"); 101 close(fd); 102 exit(-1); 103 } 104 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"); 111 close(fd); 112 exit(-1); 113 } 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"); 117 close(fd); 118 exit(-1); 119 } 120 } 121 122 close(fd); 123 return 0; 124 } 125