2 * This file is part of hayes-ril.
4 * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <utils/Log.h>
25 #include <hayes-ril.h>
27 char *ril_status_string(int status)
32 case AT_STATUS_CONNECT:
36 case AT_STATUS_CME_ERROR:
38 case AT_STATUS_INTERNAL_ERROR:
39 return "INTERNAL_ERROR";
46 void ril_recv_log(struct at_response *response)
48 char *data_string = NULL;
49 char *status_string = NULL;
50 char *error_string = NULL;
54 if(response->data_count > 0 && response->data != NULL) {
55 for(i=0 ; i < response->data_count ; i++) {
57 asprintf(&data_string, "%s", response->data[i]);
60 asprintf(&data_string, "%s, %s", string, response->data[i]);
66 if(response->status != AT_STATUS_UNDEF)
67 status_string = ril_status_string(response->status);
69 if(response->error != NULL)
70 error_string = response->error;
72 if(data_string && status_string && error_string)
73 asprintf(&string, "%s: AT RECV [\"%s\", {%s}, %s, %s]", ril_device->tag, response->command, data_string, status_string, error_string);
74 else if(data_string && status_string)
75 asprintf(&string, "%s: AT RECV [\"%s\", {%s}, %s]", ril_device->tag, response->command, data_string, status_string);
76 else if(data_string && !status_string)
77 asprintf(&string, "%s: AT RECV [\"%s\", {%s}]", ril_device->tag, response->command, data_string);
78 else if(!data_string && status_string && error_string)
79 asprintf(&string, "%s: AT RECV [\"%s\", %s, %s]", ril_device->tag, response->command, status_string, error_string);
80 else if(!data_string && status_string)
81 asprintf(&string, "%s: AT RECV [\"%s\", %s]", ril_device->tag, response->command, status_string);
83 asprintf(&string, "%s: AT RECV [\"%s\"]", ril_device->tag, response->command);
92 void ril_send_log(struct at_request *request)
94 char *data_string = NULL;
98 if(request->data != NULL)
99 data_string = (char *) request->data;
102 asprintf(&string, "%s: AT SEND [\"%s\", {%s}]", ril_device->tag, request->command, data_string);
104 asprintf(&string, "%s: AT SEND [\"%s\"]", ril_device->tag, request->command);
110 void hex_dump(void *data, int size)
112 /* dumps size bytes of *data to stdout. Looks like:
113 * [0000] 75 6E 6B 6E 6F 77 6E 20
114 * 30 FF 00 00 00 00 39 00 unknown 0.....9.
115 * (in a single line of course)
118 unsigned char *p = data;
121 char bytestr[4] = {0};
122 char addrstr[10] = {0};
123 char hexstr[ 16*3 + 5] = {0};
124 char charstr[16*1 + 5] = {0};
125 for(n=1;n<=size;n++) {
127 /* store address for this line */
128 snprintf(addrstr, sizeof(addrstr), "%.4x",
129 ((unsigned int)p-(unsigned int)data) );
133 if (isalnum(c) == 0) {
137 /* store hex str (for left side) */
138 snprintf(bytestr, sizeof(bytestr), "%02X ", *p);
139 strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1);
141 /* store char str (for right side) */
142 snprintf(bytestr, sizeof(bytestr), "%c", c);
143 strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1);
147 LOGD("[%4.4s] %-50.50s %s", addrstr, hexstr, charstr);
150 } else if(n%8 == 0) {
151 /* half line: add whitespaces */
152 strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1);
153 strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1);
158 if (strlen(hexstr) > 0) {
159 /* print rest of buffer if not empty */
160 LOGD("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr);
164 void ril_data_log(char *data, int length)
167 LOGD("%s: ==== DATA DUMP: %d BYTES ====", ril_device->tag, length);
168 hex_dump(data, length);