127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty/* 227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* Copyright (C) 2014 The Android Open Source Project 327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* 427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* Licensed under the Apache License, Version 2.0 (the "License"); 527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* you may not use this file except in compliance with the License. 627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* You may obtain a copy of the License at 727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* 827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* http://www.apache.org/licenses/LICENSE-2.0 927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* 1027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* Unless required by applicable law or agreed to in writing, software 1127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* distributed under the License is distributed on an "AS IS" BASIS, 1227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* See the License for the specific language governing permissions and 1427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty* limitations under the License. 1527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty*/ 1627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 1727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#ifndef RIL_UIM_SOCKET_H_INCLUDED 1827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#define RIL_UIM_SOCKET_H_INCLUDED 1927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#define RIL_SHLIB 2027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#include "telephony/ril.h" 2127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#include "RilSocket.h" 2227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#include <hardware/ril/librilutils/proto/sap-api.pb.h> 2327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 2427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty/** 2527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * RilSapSocket is a derived class, derived from the RilSocket abstract 2627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * class, representing sockets for communication between bluetooth SAP module and 2727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * the ril daemon. 2827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * <p> 2927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * This class performs the following functions : 3027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * <ul> 3127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * <li>Initialize the socket. 3227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * <li>Process the requests coming on the socket. 3327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * <li>Provide handlers for Unsolicited and request responses. 3427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * <li>Request and pending response queue handling. 3527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * </ul> 3627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 3727976c479473bb772703fe4caa100e535e635e84Dheeraj Shettyclass RilSapSocket : public RilSocket { 3827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 3927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Function pointer to the ril initialization funtion. 4027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 4127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Ril environment variable with place request and 4227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * response handlers and timeout handler. 4327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 4427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Number of arguements for the initialization function. 4527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 4627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Arguements to the initialization function used to 4727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * generate instance id of the ril daemon. 4827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 4927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @return Radio functions with handlers for onRequest, onStateRequest, 5027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * supports, onCancel and getVersion. 5127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 5227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_RadioFunctions *(*UimInit)(const struct RIL_Env *, int argc, char **argv); 5327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 5427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 5527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Place holder for the radio functions returned by the initialization 5627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * function. Currenty only onRequest handler is being used. 5727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 5827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_RadioFunctions* uimFuncs; 5927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 6027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 6127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Wrapper struct for handling the requests in the queue. 6227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 6327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty typedef struct SapSocketRequest { 6427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty int token; 6527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty MsgHeader* curr; 6627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty struct SapSocketRequest* p_next; 6727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_SOCKET_ID socketId; 6827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty } SapSocketRequest; 6927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 7027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 7127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Queue for requests that are pending dispatch. 7227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 7327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty Ril_queue<SapSocketRequest> dispatchQueue; 7427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 7527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 7627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Queue for requests that are dispatched but are pending response 7727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 7827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty Ril_queue<SapSocketRequest> pendingResponseQueue; 7927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 8027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty public: 8127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 8227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Initialize the socket and add the socket to the list. 8327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 8427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Name of the socket. 8527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Radio functions to be used by the socket. 8627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 8727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static void initSapSocket(const char *socketName, 8827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_RadioFunctions *uimFuncs); 8927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 9027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 9127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Ril envoronment variable that holds the request and 9227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * unsol response handlers. 9327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 9427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static struct RIL_Env uimRilEnv; 9527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 9627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 9727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Function to print the socket list. 9827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 9927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static void printList(); 10027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 10127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 102c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * Dispatches the request to the lower layers. 103c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * It calls the on request function. 104c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * 105c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * @param request The request message. 106c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan */ 107c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan void dispatchRequest(MsgHeader *request); 108c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan 109c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan /** 110c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * Class method to get the socket from the socket list. 111c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * 112c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * @param socketId Socket id. 113c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan * @return the sap socket. 114c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan */ 115c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan static RilSapSocket* getSocketById(RIL_SOCKET_ID socketId); 116c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan 117c2c71858445ae70310d11c15efaf035b4fdfcf3cAmit Mahajan /** 11827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Datatype to handle the socket list. 11927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 12027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty typedef struct RilSapSocketList { 12127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RilSapSocket* socket; 12227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RilSapSocketList *next; 12327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty } RilSapSocketList; 12427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 12527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty protected: 12627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 12727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Socket handler to be called when a request has 12827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * been completed. 12927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 13027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Token associated with the request. 13127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Error, if any, while processing the request. 13227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param The response payload. 13327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response payload length. 13427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 13527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty void onRequestComplete(RIL_Token t,RIL_Errno e, 13627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty void *response, size_t response_len); 13727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 13827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 13927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Socket handler to be called when there is an 14027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * unsolicited response. 14127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 14227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Message id. 14327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response data. 14427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response data length. 14527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 14627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty void onUnsolicitedResponse(int unsolResponse, 14727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty void *data, size_t datalen); 14827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 14927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 15027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Class method to add the sap socket to the list of sockets. 15127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Does nothing if the socket is already present in the list. 15227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Otherwise, calls the constructor of the parent class(To startlistening) 15327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * and add socket to the socket list. 15427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 15527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static void addSocketToList(const char *socketName, RIL_SOCKET_ID socketid, 15627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_RadioFunctions *uimFuncs); 15727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 15827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 15927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Check if a socket of the given name exists in the socket list. 16027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 16127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Socket name. 16227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @return true if exists, false otherwise. 16327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 16427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static bool SocketExists(const char *socketName); 16527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 16627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty private: 16727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 16827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Constructor. 16927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 17027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Socket name. 17127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Socket id. 17227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Radio functions. 17327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 17427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RilSapSocket(const char *socketName, 17527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_SOCKET_ID socketId, 17627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_RadioFunctions *inputUimFuncs); 17727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 17827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 17927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Class method that selects the socket on which the onRequestComplete 18027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * is called. 18127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 18227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Token associated with the request. 18327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Error, if any, while processing the request. 18427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param The response payload. 18527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response payload length. 18627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 18727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static void sOnRequestComplete(RIL_Token t, 18827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty RIL_Errno e, void *response, size_t responselen); 18927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 19027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#if defined(ANDROID_MULTI_SIM) 19127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 19227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Class method that selects the socket on which the onUnsolicitedResponse 19327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * is called. 19427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 19527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Message id. 19627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response data. 19727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response data length. 19827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Socket id. 19927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 20027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static void sOnUnsolicitedResponse(int unsolResponse, const void *data, 20127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty size_t datalen, RIL_SOCKET_ID socket_id); 20227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#else 20327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty /** 20427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * Class method that selects the socket on which the onUnsolicitedResponse 20527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * is called. 20627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * 20727976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Message id. 20827976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response data. 20927976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty * @param Response data length. 21027976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty */ 21127976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty static void sOnUnsolicitedResponse(int unsolResponse, const void *data, 21227976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty size_t datalen); 21327976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#endif 21427976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty}; 21527976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty 21627976c479473bb772703fe4caa100e535e635e84Dheeraj Shetty#endif /*RIL_UIM_SOCKET_H_INCLUDED*/ 217