The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1 | /* //device/system/toolbox/resetradio.c |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 8 | ** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 10 | ** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 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 */ |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 24 | #define SOCKET_NAME_RIL2_DEBUG "rild2-debug" |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 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 | |
| 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\ |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 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"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 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; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 71 | } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 5) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 72 | return 0; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 73 | } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 4) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | static int get_number_args(char *argv[]) { |
| 80 | const int option = atoi(argv[1]); |
| 81 | if (option != DIAL_CALL && option != SETUP_PDP) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 82 | return 3; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 83 | } else { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 84 | return 4; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | int main(int argc, char *argv[]) |
| 89 | { |
| 90 | int fd; |
| 91 | int num_socket_args = 0; |
| 92 | int i = 0; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 93 | int modem_socket_type = 0; |
| 94 | int sim_id = 0; |
| 95 | char socket_name[20]; |
| 96 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 97 | if(error_check(argc, argv)) { |
| 98 | print_usage(); |
| 99 | exit(-1); |
| 100 | } |
| 101 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 115 | if (fd < 0) { |
| 116 | perror ("opening radio debug socket"); |
| 117 | exit(-1); |
| 118 | } |
| 119 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 120 | |
| 121 | /* It is not necessacry to pass the argument "modem-socket style" to rild */ |
| 122 | num_socket_args--; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 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 | } |