1 /*
2  * Copyright (c) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_RIL_INTERNAL_H
18 #define ANDROID_RIL_INTERNAL_H
19 
20 namespace android {
21 
22 #define RIL_SERVICE_NAME_BASE "slot"
23 #define RIL1_SERVICE_NAME "slot1"
24 #define RIL2_SERVICE_NAME "slot2"
25 #define RIL3_SERVICE_NAME "slot3"
26 #define RIL4_SERVICE_NAME "slot4"
27 
28 /* Constants for response types */
29 #define RESPONSE_SOLICITED 0
30 #define RESPONSE_UNSOLICITED 1
31 #define RESPONSE_SOLICITED_ACK 2
32 #define RESPONSE_SOLICITED_ACK_EXP 3
33 #define RESPONSE_UNSOLICITED_ACK_EXP 4
34 
35 // Enable verbose logging
36 #define VDBG 0
37 
38 #define MIN(a,b) ((a)<(b) ? (a) : (b))
39 
40 // Enable RILC log
41 #define RILC_LOG 0
42 
43 #if RILC_LOG
44     #define startRequest           sprintf(printBuf, "(")
45     #define closeRequest           sprintf(printBuf, "%s)", printBuf)
46     #define printRequest(token, req)           \
47             RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
48 
49     #define startResponse           sprintf(printBuf, "%s {", printBuf)
50     #define closeResponse           sprintf(printBuf, "%s}", printBuf)
51     #define printResponse           RLOGD("%s", printBuf)
52 
53     #define clearPrintBuf           printBuf[0] = 0
54     #define removeLastChar          printBuf[strlen(printBuf)-1] = 0
55     #define appendPrintBuf(x...)    snprintf(printBuf, PRINTBUF_SIZE, x)
56 #else
57     #define startRequest
58     #define closeRequest
59     #define printRequest(token, req)
60     #define startResponse
61     #define closeResponse
62     #define printResponse
63     #define clearPrintBuf
64     #define removeLastChar
65     #define appendPrintBuf(x...)
66 #endif
67 
68 typedef struct CommandInfo CommandInfo;
69 
70 extern "C" const char * requestToString(int request);
71 
72 typedef struct RequestInfo {
73     int32_t token;      //this is not RIL_Token
74     CommandInfo *pCI;
75     struct RequestInfo *p_next;
76     char cancelled;
77     char local;         // responses to local commands do not go back to command process
78     RIL_SOCKET_ID socket_id;
79     int wasAckSent;    // Indicates whether an ack was sent earlier
80 } RequestInfo;
81 
82 typedef struct CommandInfo {
83     int requestNumber;
84     int(*responseFunction) (int slotId, int responseType, int token,
85             RIL_Errno e, void *response, size_t responselen);
86 } CommandInfo;
87 
88 RequestInfo * addRequestToList(int serial, int slotId, int request);
89 
90 char * RIL_getServiceName();
91 
92 void releaseWakeLock();
93 
94 void onNewCommandConnect(RIL_SOCKET_ID socket_id);
95 
96 }   // namespace android
97 
98 #endif //ANDROID_RIL_INTERNAL_H
99