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 * Process requests from the dispatch request queue.
92 * @param Request to be dispatched.
94 int processRequest(MsgHeader *request);
97 * Ril envoronment variable that holds the request and
98 * unsol response handlers.
100 static struct RIL_Env uimRilEnv;
103 * Function to print the socket list.
105 static void printList();
108 * Clean up method to be called on command close.
110 void onCommandsSocketClosed(void);
113 * Datatype to handle the socket list.
115 typedef struct RilSapSocketList {
116 RilSapSocket* socket;
117 RilSapSocketList *next;
122 * Process each record read from the socket and
123 * push a new request created from that record to
124 * the dispatch request queue.
126 * @param The record data.
127 * @param The record length.
129 void pushRecord(void *record, size_t recordlen);
132 * Socket handler to be called when a request has
135 * @param Token associated with the request.
136 * @param Error, if any, while processing the request.
137 * @param The response payload.
138 * @param Response payload length.
140 void onRequestComplete(RIL_Token t,RIL_Errno e,
141 void *response, size_t response_len);
144 * Socket handler to be called when there is an
145 * unsolicited response.
148 * @param Response data.
149 * @param Response data length.
151 void onUnsolicitedResponse(int unsolResponse,
152 void *data, size_t datalen);
155 * Class method to get the socket from the socket list.
158 * @return the sap socket.
160 static RilSapSocket* getSocketById(RIL_SOCKET_ID socketId);
163 * Method to send response to SAP. It does an atomic write operation on the
166 * @param the response header with the payload.
168 void sendResponse(MsgHeader *hdr);
171 * A loop for processing the requests in the request dispatch queue.
173 void *processRequestsLoop(void);
176 * Class method to add the sap socket to the list of sockets.
177 * Does nothing if the socket is already present in the list.
178 * Otherwise, calls the constructor of the parent class(To startlistening)
179 * and add socket to the socket list.
181 static void addSocketToList(const char *socketName, RIL_SOCKET_ID socketid,
182 RIL_RadioFunctions *uimFuncs);
185 * Check if a socket of the given name exists in the socket list.
187 * @param Socket name.
188 * @return true if exists, false otherwise.
190 static bool SocketExists(const char *socketName);
193 * Send a clean up SAP DISCONNECT if the socket disconnects before doing a SAP
196 void sendDisconnect(void);
199 * Dispatch the clean up disconnect request.
201 void dispatchDisconnect(MsgHeader *req);
208 * @param Socket name.
210 * @param Radio functions.
212 RilSapSocket(const char *socketName,
213 RIL_SOCKET_ID socketId,
214 RIL_RadioFunctions *inputUimFuncs);
217 * Called by the processRequest method to dispatch the request to
218 * the lower layers. It calls the on request function.
220 * @param The request message.
222 void dispatchRequest(MsgHeader *request);
225 * Class method that selects the socket on which the onRequestComplete
228 * @param Token associated with the request.
229 * @param Error, if any, while processing the request.
230 * @param The response payload.
231 * @param Response payload length.
233 static void sOnRequestComplete(RIL_Token t,
234 RIL_Errno e, void *response, size_t responselen);
236 #if defined(ANDROID_MULTI_SIM)
238 * Class method that selects the socket on which the onUnsolicitedResponse
242 * @param Response data.
243 * @param Response data length.
246 static void sOnUnsolicitedResponse(int unsolResponse, const void *data,
247 size_t datalen, RIL_SOCKET_ID socket_id);
250 * Class method that selects the socket on which the onUnsolicitedResponse
254 * @param Response data.
255 * @param Response data length.
257 static void sOnUnsolicitedResponse(int unsolResponse, const void *data,
262 #endif /*RIL_UIM_SOCKET_H_INCLUDED*/