xref: /aosp_15_r20/hardware/ril/libril/RilSapSocket.h (revision 062a843b36e31144e02d312b6b2de34642e6750e)
1*062a843bSAndroid Build Coastguard Worker /*
2*062a843bSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project
3*062a843bSAndroid Build Coastguard Worker *
4*062a843bSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*062a843bSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*062a843bSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*062a843bSAndroid Build Coastguard Worker *
8*062a843bSAndroid Build Coastguard Worker *     http://www.apache.org/licenses/LICENSE-2.0
9*062a843bSAndroid Build Coastguard Worker *
10*062a843bSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*062a843bSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*062a843bSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*062a843bSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*062a843bSAndroid Build Coastguard Worker * limitations under the License.
15*062a843bSAndroid Build Coastguard Worker */
16*062a843bSAndroid Build Coastguard Worker 
17*062a843bSAndroid Build Coastguard Worker #ifndef RIL_UIM_SOCKET_H_INCLUDED
18*062a843bSAndroid Build Coastguard Worker #define RIL_UIM_SOCKET_H_INCLUDED
19*062a843bSAndroid Build Coastguard Worker #define RIL_SHLIB
20*062a843bSAndroid Build Coastguard Worker #include "telephony/ril.h"
21*062a843bSAndroid Build Coastguard Worker #include "RilSocket.h"
22*062a843bSAndroid Build Coastguard Worker #include <hardware/ril/librilutils/proto/sap-api.pb.h>
23*062a843bSAndroid Build Coastguard Worker 
24*062a843bSAndroid Build Coastguard Worker /**
25*062a843bSAndroid Build Coastguard Worker  * RilSapSocket is a derived class, derived from the RilSocket abstract
26*062a843bSAndroid Build Coastguard Worker  * class, representing sockets for communication between bluetooth SAP module and
27*062a843bSAndroid Build Coastguard Worker  * the ril daemon.
28*062a843bSAndroid Build Coastguard Worker  * <p>
29*062a843bSAndroid Build Coastguard Worker  * This class performs the following functions :
30*062a843bSAndroid Build Coastguard Worker  * <ul>
31*062a843bSAndroid Build Coastguard Worker  *     <li>Initialize the socket.
32*062a843bSAndroid Build Coastguard Worker  *     <li>Process the requests coming on the socket.
33*062a843bSAndroid Build Coastguard Worker  *     <li>Provide handlers for Unsolicited and request responses.
34*062a843bSAndroid Build Coastguard Worker  *     <li>Request and pending response queue handling.
35*062a843bSAndroid Build Coastguard Worker  * </ul>
36*062a843bSAndroid Build Coastguard Worker  */
37*062a843bSAndroid Build Coastguard Worker class RilSapSocket : public RilSocket {
38*062a843bSAndroid Build Coastguard Worker     /**
39*062a843bSAndroid Build Coastguard Worker      * Place holder for the radio functions returned by the initialization
40*062a843bSAndroid Build Coastguard Worker      * function. Currenty only onRequest handler is being used.
41*062a843bSAndroid Build Coastguard Worker      */
42*062a843bSAndroid Build Coastguard Worker     const RIL_RadioFunctions* uimFuncs;
43*062a843bSAndroid Build Coastguard Worker 
44*062a843bSAndroid Build Coastguard Worker     /**
45*062a843bSAndroid Build Coastguard Worker      * Wrapper struct for handling the requests in the queue.
46*062a843bSAndroid Build Coastguard Worker      */
47*062a843bSAndroid Build Coastguard Worker     typedef struct SapSocketRequest {
48*062a843bSAndroid Build Coastguard Worker         int token;
49*062a843bSAndroid Build Coastguard Worker         MsgHeader* curr;
50*062a843bSAndroid Build Coastguard Worker         struct SapSocketRequest* p_next;
51*062a843bSAndroid Build Coastguard Worker         RIL_SOCKET_ID socketId;
52*062a843bSAndroid Build Coastguard Worker     } SapSocketRequest;
53*062a843bSAndroid Build Coastguard Worker 
54*062a843bSAndroid Build Coastguard Worker     /**
55*062a843bSAndroid Build Coastguard Worker      * Queue for requests that are pending dispatch.
56*062a843bSAndroid Build Coastguard Worker      */
57*062a843bSAndroid Build Coastguard Worker     Ril_queue<SapSocketRequest> dispatchQueue;
58*062a843bSAndroid Build Coastguard Worker 
59*062a843bSAndroid Build Coastguard Worker     /**
60*062a843bSAndroid Build Coastguard Worker      * Queue for requests that are dispatched but are pending response
61*062a843bSAndroid Build Coastguard Worker      */
62*062a843bSAndroid Build Coastguard Worker     Ril_queue<SapSocketRequest> pendingResponseQueue;
63*062a843bSAndroid Build Coastguard Worker 
64*062a843bSAndroid Build Coastguard Worker     public:
65*062a843bSAndroid Build Coastguard Worker         /**
66*062a843bSAndroid Build Coastguard Worker          * Initialize the socket and add the socket to the list.
67*062a843bSAndroid Build Coastguard Worker          *
68*062a843bSAndroid Build Coastguard Worker          * @param Name of the socket.
69*062a843bSAndroid Build Coastguard Worker          * @param Radio functions to be used by the socket.
70*062a843bSAndroid Build Coastguard Worker          */
71*062a843bSAndroid Build Coastguard Worker         static void initSapSocket(const char *socketName,
72*062a843bSAndroid Build Coastguard Worker         const RIL_RadioFunctions *uimFuncs);
73*062a843bSAndroid Build Coastguard Worker 
74*062a843bSAndroid Build Coastguard Worker         /**
75*062a843bSAndroid Build Coastguard Worker          * Ril envoronment variable that holds the request and
76*062a843bSAndroid Build Coastguard Worker          * unsol response handlers.
77*062a843bSAndroid Build Coastguard Worker          */
78*062a843bSAndroid Build Coastguard Worker         static struct RIL_Env uimRilEnv;
79*062a843bSAndroid Build Coastguard Worker 
80*062a843bSAndroid Build Coastguard Worker         /**
81*062a843bSAndroid Build Coastguard Worker          * Function to print the socket list.
82*062a843bSAndroid Build Coastguard Worker          */
83*062a843bSAndroid Build Coastguard Worker         static void printList();
84*062a843bSAndroid Build Coastguard Worker 
85*062a843bSAndroid Build Coastguard Worker         /**
86*062a843bSAndroid Build Coastguard Worker          * Dispatches the request to the lower layers.
87*062a843bSAndroid Build Coastguard Worker          * It calls the on request function.
88*062a843bSAndroid Build Coastguard Worker          *
89*062a843bSAndroid Build Coastguard Worker          * @param request The request message.
90*062a843bSAndroid Build Coastguard Worker          */
91*062a843bSAndroid Build Coastguard Worker         void dispatchRequest(MsgHeader *request);
92*062a843bSAndroid Build Coastguard Worker 
93*062a843bSAndroid Build Coastguard Worker         /**
94*062a843bSAndroid Build Coastguard Worker          * Class method to get the socket from the socket list.
95*062a843bSAndroid Build Coastguard Worker          *
96*062a843bSAndroid Build Coastguard Worker          * @param socketId Socket id.
97*062a843bSAndroid Build Coastguard Worker          * @return the sap socket.
98*062a843bSAndroid Build Coastguard Worker          */
99*062a843bSAndroid Build Coastguard Worker         static RilSapSocket* getSocketById(RIL_SOCKET_ID socketId);
100*062a843bSAndroid Build Coastguard Worker 
101*062a843bSAndroid Build Coastguard Worker         /**
102*062a843bSAndroid Build Coastguard Worker          * Datatype to handle the socket list.
103*062a843bSAndroid Build Coastguard Worker          */
104*062a843bSAndroid Build Coastguard Worker         typedef struct RilSapSocketList {
105*062a843bSAndroid Build Coastguard Worker             RilSapSocket* socket;
106*062a843bSAndroid Build Coastguard Worker             RilSapSocketList *next;
107*062a843bSAndroid Build Coastguard Worker         } RilSapSocketList;
108*062a843bSAndroid Build Coastguard Worker 
109*062a843bSAndroid Build Coastguard Worker     protected:
110*062a843bSAndroid Build Coastguard Worker         /**
111*062a843bSAndroid Build Coastguard Worker          * Socket handler to be called when a request has
112*062a843bSAndroid Build Coastguard Worker          * been completed.
113*062a843bSAndroid Build Coastguard Worker          *
114*062a843bSAndroid Build Coastguard Worker          * @param Token associated with the request.
115*062a843bSAndroid Build Coastguard Worker          * @param Error, if any, while processing the request.
116*062a843bSAndroid Build Coastguard Worker          * @param The response payload.
117*062a843bSAndroid Build Coastguard Worker          * @param Response payload length.
118*062a843bSAndroid Build Coastguard Worker          */
119*062a843bSAndroid Build Coastguard Worker         void onRequestComplete(RIL_Token t,RIL_Errno e,
120*062a843bSAndroid Build Coastguard Worker         void *response, size_t response_len);
121*062a843bSAndroid Build Coastguard Worker 
122*062a843bSAndroid Build Coastguard Worker         /**
123*062a843bSAndroid Build Coastguard Worker          * Socket handler to be called when there is an
124*062a843bSAndroid Build Coastguard Worker          * unsolicited response.
125*062a843bSAndroid Build Coastguard Worker          *
126*062a843bSAndroid Build Coastguard Worker          * @param Message id.
127*062a843bSAndroid Build Coastguard Worker          * @param Response data.
128*062a843bSAndroid Build Coastguard Worker          * @param Response data length.
129*062a843bSAndroid Build Coastguard Worker          */
130*062a843bSAndroid Build Coastguard Worker         void onUnsolicitedResponse(int unsolResponse,
131*062a843bSAndroid Build Coastguard Worker         void *data, size_t datalen);
132*062a843bSAndroid Build Coastguard Worker 
133*062a843bSAndroid Build Coastguard Worker         /**
134*062a843bSAndroid Build Coastguard Worker          * Class method to add the sap socket to the list of sockets.
135*062a843bSAndroid Build Coastguard Worker          * Does nothing if the socket is already present in the list.
136*062a843bSAndroid Build Coastguard Worker          * Otherwise, calls the constructor of the parent class(To startlistening)
137*062a843bSAndroid Build Coastguard Worker          * and add socket to the socket list.
138*062a843bSAndroid Build Coastguard Worker          */
139*062a843bSAndroid Build Coastguard Worker         static void addSocketToList(const char *socketName, RIL_SOCKET_ID socketid,
140*062a843bSAndroid Build Coastguard Worker         const RIL_RadioFunctions *uimFuncs);
141*062a843bSAndroid Build Coastguard Worker 
142*062a843bSAndroid Build Coastguard Worker         /**
143*062a843bSAndroid Build Coastguard Worker          * Check if a socket of the given name exists in the socket list.
144*062a843bSAndroid Build Coastguard Worker          *
145*062a843bSAndroid Build Coastguard Worker          * @param Socket name.
146*062a843bSAndroid Build Coastguard Worker          * @return true if exists, false otherwise.
147*062a843bSAndroid Build Coastguard Worker          */
148*062a843bSAndroid Build Coastguard Worker         static bool SocketExists(const char *socketName);
149*062a843bSAndroid Build Coastguard Worker 
150*062a843bSAndroid Build Coastguard Worker     private:
151*062a843bSAndroid Build Coastguard Worker         /**
152*062a843bSAndroid Build Coastguard Worker          * Constructor.
153*062a843bSAndroid Build Coastguard Worker          *
154*062a843bSAndroid Build Coastguard Worker          * @param Socket name.
155*062a843bSAndroid Build Coastguard Worker          * @param Socket id.
156*062a843bSAndroid Build Coastguard Worker          * @param Radio functions.
157*062a843bSAndroid Build Coastguard Worker          */
158*062a843bSAndroid Build Coastguard Worker         RilSapSocket(const char *socketName,
159*062a843bSAndroid Build Coastguard Worker         RIL_SOCKET_ID socketId,
160*062a843bSAndroid Build Coastguard Worker         const RIL_RadioFunctions *inputUimFuncs);
161*062a843bSAndroid Build Coastguard Worker 
162*062a843bSAndroid Build Coastguard Worker         /**
163*062a843bSAndroid Build Coastguard Worker          * Class method that selects the socket on which the onRequestComplete
164*062a843bSAndroid Build Coastguard Worker          * is called.
165*062a843bSAndroid Build Coastguard Worker          *
166*062a843bSAndroid Build Coastguard Worker          * @param Token associated with the request.
167*062a843bSAndroid Build Coastguard Worker          * @param Error, if any, while processing the request.
168*062a843bSAndroid Build Coastguard Worker          * @param The response payload.
169*062a843bSAndroid Build Coastguard Worker          * @param Response payload length.
170*062a843bSAndroid Build Coastguard Worker          */
171*062a843bSAndroid Build Coastguard Worker         static void sOnRequestComplete(RIL_Token t,
172*062a843bSAndroid Build Coastguard Worker         RIL_Errno e, void *response, size_t responselen);
173*062a843bSAndroid Build Coastguard Worker 
174*062a843bSAndroid Build Coastguard Worker #if defined(ANDROID_MULTI_SIM)
175*062a843bSAndroid Build Coastguard Worker         /**
176*062a843bSAndroid Build Coastguard Worker          * Class method that selects the socket on which the onUnsolicitedResponse
177*062a843bSAndroid Build Coastguard Worker          * is called.
178*062a843bSAndroid Build Coastguard Worker          *
179*062a843bSAndroid Build Coastguard Worker          * @param Message id.
180*062a843bSAndroid Build Coastguard Worker          * @param Response data.
181*062a843bSAndroid Build Coastguard Worker          * @param Response data length.
182*062a843bSAndroid Build Coastguard Worker          * @param Socket id.
183*062a843bSAndroid Build Coastguard Worker          */
184*062a843bSAndroid Build Coastguard Worker         static void sOnUnsolicitedResponse(int unsolResponse, const void *data,
185*062a843bSAndroid Build Coastguard Worker         size_t datalen, RIL_SOCKET_ID socket_id);
186*062a843bSAndroid Build Coastguard Worker #else
187*062a843bSAndroid Build Coastguard Worker         /**
188*062a843bSAndroid Build Coastguard Worker          * Class method that selects the socket on which the onUnsolicitedResponse
189*062a843bSAndroid Build Coastguard Worker          * is called.
190*062a843bSAndroid Build Coastguard Worker          *
191*062a843bSAndroid Build Coastguard Worker          * @param Message id.
192*062a843bSAndroid Build Coastguard Worker          * @param Response data.
193*062a843bSAndroid Build Coastguard Worker          * @param Response data length.
194*062a843bSAndroid Build Coastguard Worker          */
195*062a843bSAndroid Build Coastguard Worker         static void sOnUnsolicitedResponse(int unsolResponse, const void *data,
196*062a843bSAndroid Build Coastguard Worker         size_t datalen);
197*062a843bSAndroid Build Coastguard Worker #endif
198*062a843bSAndroid Build Coastguard Worker };
199*062a843bSAndroid Build Coastguard Worker 
200*062a843bSAndroid Build Coastguard Worker #endif /*RIL_UIM_SOCKET_H_INCLUDED*/
201