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:

# Define log_tag "rilc" </P> <p> # include <pardware_legacy/power. h> </P> <p> # include <telephony/RIL. h> <br/> # include <telephony/ril_cdma _sms.h> <br/> # include <cutils/sockets. h> <br/> # include <cutils/jstring. h> <br/> # include <cutils/record_stream.h> <br/> # include <utils/log. h> <br/> # include <utils/systemclock. h> <br/> # include <pthread. h> <br/> # include <binder/parcel. h> <br/> # include <cutils/jstring. h> </P> <P> # include <sys/types. h> <br/> # include <PWD. h> </P> <p> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include <stdarg. h> <br/> # include <string. h> <br/> # include <unistd. h> <br/> # include <fcntl. h> <br/> # include <time. h> <br/> # include <errno. h> <br/> # include <assert. h> <br/> # include <ctype. h> <br/> # include <alloca. h> <br/> # include <sys/UN. h> <br/> # include <assert. h> <br/> # include <netinet/in. h> <br /># Include <cutils/properties. h> </P> <p> # include <ril_event.h> </P> <p> namespace Android {</P> <p> # define phone_process "radio" </P> <p> # define socket_name_ril "rild" <br/> # define socket_name_ril_debug "rild-Debug" </P> <p> # define android_wake_lock_name "radio-Interface" </P> <p> # define property_ril_impl "GSM. version. RIL-impl "</P> <p> // match with constant in RIL. java <br/> # define max_command_bytes (8*1024) </P> <p> // basically: memset buffers that the client library <br/> // shouldn't be using anymore in an attempt to find <br/> // memory usage issues sooner. <br/> # define memset_freed 1 </P> <p> // common method for getting the number of array elements <br/> # define num_elems (A) (sizeof () /sizeof (a) [0]) </P> <p> // returns a smaller number. <br/> # define min (A, B) () <(B )? (A): (B) </P> <p>/* reply type: requested and unrequested responses */<br/> # define response_solicited 0 <br/> # define response_unsolicited 1 </P> <p>/* negative values for private RIL errno's */<br/> # define ril_errno_invalid_response-1 </P> <p> // request, response, and unsolicited MSG print macro <br/> // print the size of the printbuf buffer <br/> # define printbuf_size 8096 </P> <p> // enable rilc log <br/> # define rilc_log 0 </P> <p> # If rilc_log <br/> // The Call Sequence of the three macros is startrequest-printrequest-closerequest <br/> //. the printed Request command will be included in () <br/> # define startrequest sprintf (printbuf, "(") <br/> # define closerequest sprintf (printbuf, "% s)", printbuf) <br/> # define printrequest (token, req) \ <br/> logd ("[% 04d]> % S % s", Token, requesttostring (req), printbuf) <br/> // The Call Sequence of the three macros is startresponse-printresponse-closeresponse <br/> // The printed reply information will be included in {}. <br/> # define startresponse sprintf (printbuf, "% s {", printbuf) <br/> # define closeresponse sprintf (printbuf, "% s}", printbuf) <br/> # define printresponse logd ("% s", printbuf) </P> <p> # define clearprintbuf printbuf [0] = 0 <br/> # define removelastchar printbuf [strlen (printbuf) -1] = 0 <br/> # define appendprintbuf (X ...) sprintf (printbuf, x) <br/> # else <br/> # define startrequest <br/> # define closerequest <br/> # define printrequest (token, req) <br/> # define startresponse <br/> # define closeresponse <br/> # define printresponse <br/> # define clearprintbuf <br/> # define removelastchar <br/> # define appendprintbuf (X ...) <br/> # endif </P> <p> // wakeup type: do not wake up, partially wake up <br/> Enum waketype {dont_wake, wake_partial }; </P> <p> // "requested reply" struct definition: Request number, command distribution processing function, response Function of the returned result <br/> // for the value of this struct, see the ril_commands.h file <br/> typedef struct {<br/> int requestnumber; <br/> void (* dispatchfunction) (parcel & P, struct requestinfo * Pri); <br/> int (* responsefunction) (parcel & P, void * response, size_t responselen); <br/>} commandinfo; </P> <p> // "unrequested reply" struct definition: Request number, event response function, wake-up type <br/> // for the value of this struct, see the ril_unsol_commands.h file <br/> typedef struct {<br/> int requestnumber; <br/> int (* responsefunction) (parcel & P, void * response, size_t responselen); <br/> waketype; <br/>} unsolresponseinfo; </P> <p> // request information structure, encapsulate commandinfo and concatenate it into a linked list <br/> typedef struct requestinfo {<br/> int32_t token; // This Is Not ril_token <br/> commandinfo * PCI; <br/> struct requestinfo * p_next; <br/> char canceled; <br/> char local; // responses to local commands do not go back to command Process <br/>} requestinfo; </P> <p> // user callback information structure <br/> typedef struct usercallbackinfo {<br/> ril_timedcallback p_callback; // callback function <br/> void * userparam; // callback function parameter <br/> struct ril_event event; // RIL event <br/> struct usercallbackinfo * p_next; // point to the next Callback information structure (linked list form) <br/>} usercallbackinfo; </P> <p> /******************************** *********************************/<br/> // initialize the callback structure <br/> ril_radiofunctions s_callbacks = {0, null, null, null }; <br/> static int s_registercalled = 0; </P> <p> static pthread_t s_tid_dispatch; // distribution processing thread id <br/> static pthread_t s_tid_reader; // reader thread id <br/> static int s_started = 0; </P> <p> // file descriptor initialization <br/> static int s_fdlisten =-1; <br/> static int s_fdcommand =-1; <br/> static int s_fddebug =-1; </P> <p> static int s_fdwakeupread; <br/> static int s_fdwakeupwrite; </P> <p> // five related events <br/> static struct ril_event s_commands_event; <br/> static struct ril_event s_wakeupfd_event; <br/> static struct ril_event s_listen_event; <br/> static struct ril_event s_wake_timeout_event; <br/> static struct ril_event s_debug_event; </P> <p> static const struct timeval timeval_wake_timeout = {1, 0 }; </P> <p> // initialize mutex and condition variable <br/> static pthread_mutex_t s_pendingrequestsmutex = pthread_mutex_initializer; <br/> static pthread_mutex_t s_writemutex = conflict; <br/> static pthread_mutex_t s_startupmutex = signature; <br/> static pthread_cond_t s_startupcond = signature; </P> <p> static pthread_mutex_t s_dispatchmutex = signature; <br/> static pthread_cond_t s_dispatchcond = pthread_cond_initializer; </P> <p> static requestinfo * s_pendingrequests = NULL; </P> <p> static requestinfo * s_todispatchhead = NULL; <br/> static requestinfo * s_todispatchtail = NULL; </P> <p> static usercallbackinfo * s_last_wake_timeout_info = NULL; </P> <p> static void * s_lastnitztimedata = NULL; <br/> static size_t s_lastnitztimedatasize; </P> <p> # If rilc_log <br/> static char printbuf [printbuf_size]; // array of cached print information <br/> # endif </P> <p> /******************* **************************************** * ******/<br/> // The dispatch * series functions are the processing functions of the baseband processor for processing application processor requests. <br/> static void dispatchvoid (parcel & P, requestinfo * Pri); <br/> static void dispatchstring (parcel & P, requestinfo * Pri); <br/> static void dispatchstrings (parcel & P, requestinfo * Pri ); <br/> static void dispatchints (parcel & P, requestinfo * Pri); <br/> static void dispatchdial (parcel & P, requestinfo * Pri ); <br/> static void dispatchsim_io (parcel & P, requestinfo * Pri); <br/> static void dispatchcallforward (parcel & P, requestinfo * Pri ); <br/> static void dispatchraw (parcel & P, requestinfo * Pri); <br/> static void dispatchsmswrite (parcel & P, requestinfo * Pri ); </P> <p> static void dispatchcdmasms (parcel & P, requestinfo * Pri); <br/> static void dispatchcdmasmsack (parcel & P, requestinfo * Pri ); <br/> static void dispatchgsmbrsmscnf (parcel & P, requestinfo * Pri); <br/> static void dispatchcdmabrsmscnf (parcel & P, requestinfo * Pri ); <br/> static void dispatchrilcdmasmswriteargs (parcel & P, requestinfo * Pri ); </P> <p> // response * series functions are the response functions of the application processor to the message of the baseband processor. <br/> // include the request response function and Event Response Function. <br /> static int responseints (parcel & P, void * response, size_t responselen); <br/> static int responsestrings (parcel & P, void * response, size_t responselen); <br/> static int responsestring (parcel & P, void * response, size_t responselen); <br/> static int responsevoid (parcel & P, void * response, size_t responselen); <br/> static int responsecalllist (parcel & P, void * response, size_t responselen); <br/> static int responsesms (parcel & P, void * response, size_t responselen); <br/> static int responsesim_io (parcel & P, void * response, size_t responselen); <br/> static int responsecallforwards (parcel & P, void * response, size_t responselen); <br/> static int responsedatacalllist (parcel & P, void * response, size_t responselen); <br/> static int responseraw (parcel & P, void * response, size_t responselen); <br/> static int responsessn (parcel & P, void * response, size_t responselen); <br/> static int responsesimstatus (parcel & P, void * response, size_t responselen); <br/> static int responsegsmbrsmscnf (parcel & P, void * response, size_t responselen); <br/> static int responsecdmabrsmscnf (parcel & P, void * response, size_t responselen); <br/> static int responsecdmasms (parcel & P, void * response, size_t responselen); <br/> static int responsecelllist (parcel & P, void * response, size_t responselen); <br/> static int responsecdma informationrecords (parcel & P, void * response, size_t responselen); <br/> static int responserilsignalstrength (parcel & P, void * response, size_t responselen); <br/> static int responsecallring (parcel & P, void * response, size_t response); <br/> static int responsecdmasignalinforecord (parcel & P, void * response, size_t responselen); <br/> static int responsecdmacwaitalling (parcel & P, void * response, size_t responselen ); </P> <p> // convert data structure information into string output <br/> extern "C" const char * requesttostring (INT request ); <br/> extern "C" const char * failcausetostring (ril_errno); <br/> extern "C" const char * callstatetostring (ril_callstate ); <br/> extern "C" const char * radiostatetostring (ril_radiostate); </P> <p> # ifdef ril_shlib <br/> extern "C" Void merge (INT unsolresponse, void * data, <br/> size_t datalen); <br/> # endif </P> <p> static usercallbackinfo * internalrequesttimedcallback <br/> (ril_timedcallback callback, void * Param, <br/> const struct timeval * relativetime ); </P> <p>/** Index = requestnumber */<br/> // a good usage. Because there are too many array elements, the code is neat and clear, <br/> // put the definition of the array element in a separate header file, use # include to <br/> static commandinfo s_commands [] ={< br/> # include "ril_commands.h" <br/> }; </P> <p> static unsolresponseinfo s_unsolresponses [] ={< br/> # include "ril_unsol_commands.h" <br/> };

To be continued

 

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.