Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 RIL_UIM_SOCKET_H_INCLUDED |
| 18 | #define RIL_UIM_SOCKET_H_INCLUDED |
| 19 | #define RIL_SHLIB |
| 20 | #include "telephony/ril.h" |
| 21 | #include "RilSocket.h" |
| 22 | #include <hardware/ril/librilutils/proto/sap-api.pb.h> |
| 23 | |
| 24 | /** |
| 25 | * RilSapSocket is a derived class, derived from the RilSocket abstract |
| 26 | * class, representing sockets for communication between bluetooth SAP module and |
| 27 | * the ril daemon. |
| 28 | * <p> |
| 29 | * This class performs the following functions : |
| 30 | * <ul> |
| 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. |
| 35 | * </ul> |
| 36 | */ |
| 37 | class RilSapSocket : public RilSocket { |
| 38 | /** |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 39 | * Place holder for the radio functions returned by the initialization |
| 40 | * function. Currenty only onRequest handler is being used. |
| 41 | */ |
Nathan Harold | ea60787 | 2017-07-31 19:44:46 -0700 | [diff] [blame] | 42 | const RIL_RadioFunctions* uimFuncs; |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Wrapper struct for handling the requests in the queue. |
| 46 | */ |
| 47 | typedef struct SapSocketRequest { |
| 48 | int token; |
| 49 | MsgHeader* curr; |
| 50 | struct SapSocketRequest* p_next; |
| 51 | RIL_SOCKET_ID socketId; |
| 52 | } SapSocketRequest; |
| 53 | |
| 54 | /** |
| 55 | * Queue for requests that are pending dispatch. |
| 56 | */ |
| 57 | Ril_queue<SapSocketRequest> dispatchQueue; |
| 58 | |
| 59 | /** |
| 60 | * Queue for requests that are dispatched but are pending response |
| 61 | */ |
| 62 | Ril_queue<SapSocketRequest> pendingResponseQueue; |
| 63 | |
| 64 | public: |
| 65 | /** |
| 66 | * Initialize the socket and add the socket to the list. |
| 67 | * |
| 68 | * @param Name of the socket. |
| 69 | * @param Radio functions to be used by the socket. |
| 70 | */ |
| 71 | static void initSapSocket(const char *socketName, |
Nathan Harold | ea60787 | 2017-07-31 19:44:46 -0700 | [diff] [blame] | 72 | const RIL_RadioFunctions *uimFuncs); |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 73 | |
| 74 | /** |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 75 | * Ril envoronment variable that holds the request and |
| 76 | * unsol response handlers. |
| 77 | */ |
| 78 | static struct RIL_Env uimRilEnv; |
| 79 | |
| 80 | /** |
| 81 | * Function to print the socket list. |
| 82 | */ |
| 83 | static void printList(); |
| 84 | |
| 85 | /** |
Martin Bouchet | 0d4bbaf | 2017-09-23 04:54:37 -0300 | [diff] [blame] | 86 | * Dispatches the request to the lower layers. |
| 87 | * It calls the on request function. |
| 88 | * |
| 89 | * @param request The request message. |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 90 | */ |
Martin Bouchet | 0d4bbaf | 2017-09-23 04:54:37 -0300 | [diff] [blame] | 91 | void dispatchRequest(MsgHeader *request); |
| 92 | |
| 93 | /** |
| 94 | * Class method to get the socket from the socket list. |
| 95 | * |
| 96 | * @param socketId Socket id. |
| 97 | * @return the sap socket. |
| 98 | */ |
| 99 | static RilSapSocket* getSocketById(RIL_SOCKET_ID socketId); |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Datatype to handle the socket list. |
| 103 | */ |
| 104 | typedef struct RilSapSocketList { |
| 105 | RilSapSocket* socket; |
| 106 | RilSapSocketList *next; |
| 107 | } RilSapSocketList; |
| 108 | |
| 109 | protected: |
| 110 | /** |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 111 | * Socket handler to be called when a request has |
| 112 | * been completed. |
| 113 | * |
| 114 | * @param Token associated with the request. |
| 115 | * @param Error, if any, while processing the request. |
| 116 | * @param The response payload. |
| 117 | * @param Response payload length. |
| 118 | */ |
| 119 | void onRequestComplete(RIL_Token t,RIL_Errno e, |
| 120 | void *response, size_t response_len); |
| 121 | |
| 122 | /** |
| 123 | * Socket handler to be called when there is an |
| 124 | * unsolicited response. |
| 125 | * |
| 126 | * @param Message id. |
| 127 | * @param Response data. |
| 128 | * @param Response data length. |
| 129 | */ |
| 130 | void onUnsolicitedResponse(int unsolResponse, |
| 131 | void *data, size_t datalen); |
| 132 | |
| 133 | /** |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 134 | * Class method to add the sap socket to the list of sockets. |
| 135 | * Does nothing if the socket is already present in the list. |
| 136 | * Otherwise, calls the constructor of the parent class(To startlistening) |
| 137 | * and add socket to the socket list. |
| 138 | */ |
| 139 | static void addSocketToList(const char *socketName, RIL_SOCKET_ID socketid, |
Nathan Harold | ea60787 | 2017-07-31 19:44:46 -0700 | [diff] [blame] | 140 | const RIL_RadioFunctions *uimFuncs); |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * Check if a socket of the given name exists in the socket list. |
| 144 | * |
| 145 | * @param Socket name. |
| 146 | * @return true if exists, false otherwise. |
| 147 | */ |
| 148 | static bool SocketExists(const char *socketName); |
| 149 | |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 150 | private: |
| 151 | /** |
| 152 | * Constructor. |
| 153 | * |
| 154 | * @param Socket name. |
| 155 | * @param Socket id. |
| 156 | * @param Radio functions. |
| 157 | */ |
| 158 | RilSapSocket(const char *socketName, |
| 159 | RIL_SOCKET_ID socketId, |
Nathan Harold | ea60787 | 2017-07-31 19:44:46 -0700 | [diff] [blame] | 160 | const RIL_RadioFunctions *inputUimFuncs); |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 161 | |
| 162 | /** |
Dheeraj Shetty | cc23101 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 163 | * Class method that selects the socket on which the onRequestComplete |
| 164 | * is called. |
| 165 | * |
| 166 | * @param Token associated with the request. |
| 167 | * @param Error, if any, while processing the request. |
| 168 | * @param The response payload. |
| 169 | * @param Response payload length. |
| 170 | */ |
| 171 | static void sOnRequestComplete(RIL_Token t, |
| 172 | RIL_Errno e, void *response, size_t responselen); |
| 173 | |
| 174 | #if defined(ANDROID_MULTI_SIM) |
| 175 | /** |
| 176 | * Class method that selects the socket on which the onUnsolicitedResponse |
| 177 | * is called. |
| 178 | * |
| 179 | * @param Message id. |
| 180 | * @param Response data. |
| 181 | * @param Response data length. |
| 182 | * @param Socket id. |
| 183 | */ |
| 184 | static void sOnUnsolicitedResponse(int unsolResponse, const void *data, |
| 185 | size_t datalen, RIL_SOCKET_ID socket_id); |
| 186 | #else |
| 187 | /** |
| 188 | * Class method that selects the socket on which the onUnsolicitedResponse |
| 189 | * is called. |
| 190 | * |
| 191 | * @param Message id. |
| 192 | * @param Response data. |
| 193 | * @param Response data length. |
| 194 | */ |
| 195 | static void sOnUnsolicitedResponse(int unsolResponse, const void *data, |
| 196 | size_t datalen); |
| 197 | #endif |
| 198 | }; |
| 199 | |
| 200 | #endif /*RIL_UIM_SOCKET_H_INCLUDED*/ |