2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef RIL_UIM_SOCKET_H_INCLUDED
18 #define RIL_UIM_SOCKET_H_INCLUDED
20 #include "telephony/ril.h"
21 #include "RilSocket.h"
22 #include <hardware/ril/librilutils/proto/sap-api.pb.h>
25 * RilSapSocket is a derived class, derived from the RilSocket abstract
26 * class, representing sockets for communication between bluetooth SAP module and
29 * This class performs the following functions :
31 * <li>Initialize the socket.
32 * <li>Process the requests coming on the socket.
33 * <li>Provide handlers for Unsolicited and request responses.
34 * <li>Request and pending response queue handling.
37 class RilSapSocket : public RilSocket {
39 * Function pointer to the ril initialization funtion.
41 * @param Ril environment variable with place request and
42 * response handlers and timeout handler.
44 * @param Number of arguements for the initialization function.
46 * @param Arguements to the initialization function used to
47 * generate instance id of the ril daemon.
49 * @return Radio functions with handlers for onRequest, onStateRequest,
50 * supports, onCancel and getVersion.
52 RIL_RadioFunctions *(*UimInit)(const struct RIL_Env *, int argc, char **argv);
55 * Place holder for the radio functions returned by the initialization
56 * function. Currenty only onRequest handler is being used.
58 RIL_RadioFunctions* uimFuncs;
61 * Wrapper struct for handling the requests in the queue.
63 typedef struct SapSocketRequest {
66 struct SapSocketRequest* p_next;
67 RIL_SOCKET_ID socketId;
71 * Queue for requests that are pending dispatch.
73 Ril_queue<SapSocketRequest> dispatchQueue;
76 * Queue for requests that are dispatched but are pending response
78 Ril_queue<SapSocketRequest> pendingResponseQueue;
82 * Initialize the socket and add the socket to the list.
84 * @param Name of the socket.
85 * @param Radio functions to be used by the socket.
87 static void initSapSocket(const char *socketName,
88 RIL_RadioFunctions *uimFuncs);
91 * Ril envoronment variable that holds the request and
92 * unsol response handlers.
94 static struct RIL_Env uimRilEnv;
97 * Function to print the socket list.
99 static void printList();
102 * Clean up method to be called on command close.
104 void onCommandsSocketClosed(void);
107 * Datatype to handle the socket list.
109 typedef struct RilSapSocketList {
110 RilSapSocket* socket;
111 RilSapSocketList *next;
116 * Process each record read from the socket and
117 * push a new request created from that record to
118 * the dispatch request queue.
120 * @param The record data.
121 * @param The record length.
123 void pushRecord(void *record, size_t recordlen);
126 * Socket handler to be called when a request has
129 * @param Token associated with the request.
130 * @param Error, if any, while processing the request.
131 * @param The response payload.
132 * @param Response payload length.
134 void onRequestComplete(RIL_Token t,RIL_Errno e,
135 void *response, size_t response_len);
138 * Socket handler to be called when there is an
139 * unsolicited response.
142 * @param Response data.
143 * @param Response data length.
145 void onUnsolicitedResponse(int unsolResponse,
146 void *data, size_t datalen);
149 * Class method to get the socket from the socket list.
152 * @return the sap socket.
154 static RilSapSocket* getSocketById(RIL_SOCKET_ID socketId);
157 * Method to send response to SAP. It does an atomic write operation on the
160 * @param the response header with the payload.
162 void sendResponse(MsgHeader *hdr);
165 * A loop for processing the requests in the request dispatch queue.
167 void *processRequestsLoop(void);
170 * Class method to add the sap socket to the list of sockets.
171 * Does nothing if the socket is already present in the list.
172 * Otherwise, calls the constructor of the parent class(To startlistening)
173 * and add socket to the socket list.
175 static void addSocketToList(const char *socketName, RIL_SOCKET_ID socketid,
176 RIL_RadioFunctions *uimFuncs);
179 * Check if a socket of the given name exists in the socket list.
181 * @param Socket name.
182 * @return true if exists, false otherwise.
184 static bool SocketExists(const char *socketName);
187 * Send a clean up SAP DISCONNECT if the socket disconnects before doing a SAP
190 void sendDisconnect(void);
193 * Dispatch the clean up disconnect request.
195 void dispatchDisconnect(MsgHeader *req);
202 * @param Socket name.
204 * @param Radio functions.
206 RilSapSocket(const char *socketName,
207 RIL_SOCKET_ID socketId,
208 RIL_RadioFunctions *inputUimFuncs);
211 * Dispatches the request to the lower layers.
212 * It calls the on request function.
214 * @param The request message.
216 void dispatchRequest(MsgHeader *request);
219 * Class method that selects the socket on which the onRequestComplete
222 * @param Token associated with the request.
223 * @param Error, if any, while processing the request.
224 * @param The response payload.
225 * @param Response payload length.
227 static void sOnRequestComplete(RIL_Token t,
228 RIL_Errno e, void *response, size_t responselen);
230 #if defined(ANDROID_MULTI_SIM)
232 * Class method that selects the socket on which the onUnsolicitedResponse
236 * @param Response data.
237 * @param Response data length.
240 static void sOnUnsolicitedResponse(int unsolResponse, const void *data,
241 size_t datalen, RIL_SOCKET_ID socket_id);
244 * Class method that selects the socket on which the onUnsolicitedResponse
248 * @param Response data.
249 * @param Response data length.
251 static void sOnUnsolicitedResponse(int unsolResponse, const void *data,
256 #endif /*RIL_UIM_SOCKET_H_INCLUDED*/