Android RIL source code Research Note mongoril (1)

Source: Internet
Author: User

The Android source code directory hardware/ril/libril contains a total of five C/CPP files: ril_commands.h, ril_unsol_commands.h, ril_event.h, ril_event.cpp, and ril. cpp. This article mainly analyzes the ril. cpp file.
We can divide the file into the definition part and the implementation part. Let's look at the definition part first:
[Cpp]
# Define LOG_TAG "RILC"
 
# Include  
# Include <telephony/ril. h>
# Include <telephony/ril_cdma _sms.h>
# Include <cutils/sockets. h>
# Include <cutils/jstring. h>
# Include <cutils/record_stream.h>
# Include <utils/Log. h>
# Include <utils/SystemClock. h>
# Include <pthread. h>
# Include <binder/Parcel. h>
# Include <cutils/jstring. h>
 
# Include <sys/types. h>
# Include <pwd. h>
 
# Include <stdio. h>
# Include <stdlib. h>
# Include <stdarg. h>
# Include <string. h>
# Include <unistd. h>
# Include <fcntl. h>
# Include <time. h>
# Include <errno. h>
# Include <assert. h>
# Include <ctype. h>
# Include <alloca. h>
# Include <sys/un. h>
# Include <assert. h>
# Include <netinet/in. h>
# Include <cutils/properties. h>
 
# Include <ril_event.h>
 
Namespace android {
 
# Define PHONE_PROCESS "radio"
 
# Define SOCKET_NAME_RIL "rild"
# Define SOCKET_NAME_RIL_DEBUG "rild-debug"
 
# Define ANDROID_WAKE_LOCK_NAME "radio-interface"
 
# Define PROPERTY_RIL_IMPL "gsm. version. ril-impl"
 
// Match with constant in RIL. java
# Define MAX_COMMAND_BYTES (8*1024)
 
// Basically: memset buffers that the client library
// Shouldn't be using anymore in an attempt to find
// Memory usage issues sooner.
# Define MEMSET_FREED 1
 
// A common method for getting the number of array elements
# Define NUM_ELEMS (a) (sizeof (a)/sizeof (a) [0])
 
// Returns a smaller value.
# Define MIN (a, B) (a) <(B )? (A): (B ))
 
/* WWW.2CTO. COM reply type: requested reply and unrequested reply */
# Define RESPONSE_SOLICITED 0
# Define RESPONSE_UNSOLICITED 1
 
/* Negative values for private RIL errno's */
# Define RIL_ERRNO_INVALID_RESPONSE-1
 
// Request, response, and unsolicited msg print macro
// Print the size of the printBuf buffer.
# Define PRINTBUF_SIZE 8096
 
// Enable RILC log
# Define RILC_LOG 0
 
# If RILC_LOG
// The Call Sequence of the three macros is startRequest-printRequest-closeRequest.
// The printed Request command will be included in ().
# Define startRequest sprintf (printBuf ,"(")
# Define closeRequest sprintf (printBuf, "% s)", printBuf)
# Define printRequest (token, req )\
LOGD ("[% 04d]> % s", token, requestToString (req), printBuf)
// The Call Sequence of the three macros is startResponse-printResponse-closeResponse.
// The printed reply information will be included in {}.
# Define startResponse sprintf (printBuf, "% s {", printBuf)
# Define closeResponse sprintf (printBuf, "% s}", printBuf)
# Define printResponse LOGD ("% s", printBuf)
 
# Define clearPrintBuf printBuf [0] = 0
# Define removeLastChar printBuf [strlen (printBuf)-1] = 0
# Define appendPrintBuf (x...) sprintf (printBuf, x)
# Else
# Define startRequest
# Define closeRequest
# Define printRequest (token, req)
# Define startResponse
# Define closeResponse
# Define printResponse
# Define clearPrintBuf
# Define removeLastChar
# Define appendPrintBuf (x ...)
# Endif
 
// Wakeup type: do not wake up, partially wake up
Enum WakeType {DONT_WAKE, WAKE_PARTIAL };
 
// "Requested reply" struct definition: Request number, command distribution processing function, return result Response Function
// For the value of this struct, see the ril_commands.h file.
Typedef struct {
Int requestNumber;
Void (* dispatchFunction) (Parcel & p, struct RequestInfo * pRI );
Int (* responseFunction) (Parcel & p, void * response, size_t responselen );
} CommandInfo;
 
// "Unrequested reply" struct definition: Request number, Event Response Function, wake-up type
// For the value of this struct, see the ril_unsol_commands.h file.
Typedef struct {
Int requestNumber;
Int (* responseFunction) (Parcel & p, void * response, size_t responselen );
WakeType wakeType;
} UnsolResponseInfo;
 
// Request information structure, which encapsulates CommandInfo and concatenates it into a linked list
Typedef struct RequestInfo {
Int32_t token; // this is not RIL_Token
CommandInfo * pCI;
Struct RequestInfo * p_next;
Char canceled;
Char local; // responses to local commands do not go back to command process
} RequestInfo;
 
// Structure of user callback Information
Typedef struct UserCallbackInfo {
RIL_TimedCallback p_callback; // callback function
Void * userParam; // callback function parameter
Struct ril_event event; // ril event
Struct UserCallbackInfo * p_next; // point to the next Callback information structure (Linked List)
} UserCallbackInfo;
 
/*************************************** ****************************/
// Initialize the callback Structure
RIL_RadioFunctions s_callbacks = {0, NULL, NULL };
Static int s_registerCalled = 0;
 
Static pthread_t s_tid_dispatch; // distribution processing thread ID
Static pthread_t s_tid_reader; // reader thread ID
Static int s_started = 0;
 
// File descriptor Initialization
Static int s_fdListen =-1;
Static int s_fdCommand =-1;
Static int s_fdDebug =-1;
 
Static int s_fdWakeupRead;
Static int s_fdWakeupWrite;
 
// Five related events
Static struct ril_event s_commands_event;
Static struct ril_event s_wakeupfd_event;
Static struct ril_event s_listen_event;
Static struct ril_event s_wake_timeout_event;
Static struct ril_event s_debug_event;
 
 
Static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1, 0 };
 
// Initialize mutex and conditional variables
Static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
Static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
Static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
 
Static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
Static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
 
Static RequestInfo * s_pendingRequests = NULL;
 
Static RequestInfo * s_toDispatchHead = NULL;
Static RequestInfo * s_toDispatchTail = NULL;
 
Static UserCallbackInfo * s_last_wake_timeout_info = NULL;
 
Static void * s_lastNITZTimeData = NULL;
Static size_t s_lastNITZTimeDataSize;
 
# If RILC_LOG
Static char printBuf [PRINTBUF_SIZE]; // cache the array of printed information
# Endif
 
/*************************************** ****************************/
// Dispatch * series functions are the processing functions of the baseband processor for application processor requests.
Static void dispatchVoid (Parcel & p, RequestInfo * pRI );
Static void dispatchString (Parcel & p, RequestInfo * pRI );
Static void dispatchStrings (Parcel & p, RequestInfo * pRI );
Static void dispatchInts (Parcel & p, RequestInfo * pRI );
Static void dispatchDial (Parcel & p, RequestInfo * pRI );
Static void dispatchSIM_IO (Parcel & p, RequestInfo * pRI );
Static void dispatchCallForward (Parcel & p, RequestInfo * pRI );
Static void dispatchRaw (Parcel & p, RequestInfo * pRI );
Static void dispatchSmsWrite (Parcel & p, RequestInfo * pRI );
 
Static void dispatchCdmaSms (Parcel & p, RequestInfo * pRI );
Static void dispatchCdmaSmsAck (Parcel & p, RequestInfo * pRI );
Static void dispatchGsmBrSmsCnf (Parcel & p, RequestInfo * pRI );
Static void dispatchCdmaBrSmsCnf (Parcel & p, RequestInfo * pRI );
Static void dispatchRilCdmaSmsWriteArgs (Parcel & p, RequestInfo * pRI );
 
// Response * series functions are the response functions of the application processor to messages of the baseband processor.
// Includes the Request Response Function and Event Response Function
Static int responseInts (Parcel & p, void * response, size_t responselen );
Static int responseStrings (Parcel & p, void * response, size_t responselen );
Static int responseString (Parcel & p, void * response, size_t responselen );
Static int responseVoid (Parcel & p, void * response, size_t responselen );
Static int responseCallList (Parcel & p, void * response, size_t responselen );
Static int responseSMS (Parcel & p, void * response, size_t responselen );
Static int responseSIM_IO (Parcel & p, void * response, size_t responselen );
Static int responseCallForwards (Parcel & p, void * response, size_t responselen );
Static int responseDataCallList (Parcel & p, void * response, size_t responselen );
Static int responseRaw (Parcel & p, void * response, size_t responselen );
Static int responseSsn (Parcel & p, void * response, size_t responselen );
Static int responseSimStatus (Parcel & p, void * response, size_t responselen );
Static int responseGsmBrSmsCnf (Parcel & p, void * response, size_t responselen );
Static int responseCdmaBrSmsCnf (Parcel & p, void * response, size_t responselen );
Static int responseCdmaSms (Parcel & p, void * response, size_t responselen );
Static int responseCellList (Parcel & p, void * response, size_t responselen );
Static int responsecdma informationrecords (Parcel & p, void * response, size_t responselen );
Static int responseRilSignalStrength (Parcel & p, void * response, size_t responselen );
Static int responseCallRing (Parcel & p, void * response, size_t responselen );
Static int responseCdmaSignalInfoRecord (Parcel & p, void * response, size_t responselen );
Static int responseCdmaCallWaiting (Parcel & p, void * response, size_t responselen );
 
// Convert data structure information into string output
Extern "C" const char * requestToString (int request );
Extern "C" const char * failCauseToString (RIL_Errno );
Extern "C" const char * callStateToString (RIL_CallState );
Extern "C" const char * radioStateToString (RIL_RadioState );
 
# Ifdef RIL_SHLIB
Extern "C" void RIL_onUnsolicitedResponse (int unsolResponse, void * data,
Size_t datalen );
# Endif
 
Static UserCallbackInfo * internalRequestTimedCallback
(RIL_TimedCallback callback, void * param,
Const struct timeval * relativeTime );
 
/** Index = requestNumber */
// A good usage. Because there are too many array elements, the code should be clean and clear,
// Put the definition of the array element in a separate header file and use # include
Static CommandInfo s_commands [] = {
# Include "ril_commands.h"
};
 
Static UnsolResponseInfo s_unsolResponses [] = {
# Include "ril_unsol_commands.h"
};

From ASCE1885's column

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.