blob: 38b8c3b67757b9a24cee041d75e84e0f4dabdf0b [file] [log] [blame]
David Warren5f6ca4f2009-04-30 17:11:58 -07001page.title=Radio Layer Interface
2pdk.version=1.0
3@jd:body
4
5<a name="toc"/>
6<div style="padding:10px">
7<a href="#androidTelephonyIntro">Introduction</a><br/>
8<a href="#androidTelephonyRILInitialization">RIL Initialization</a><br/>
9<a href="#androidTelephonyRILIntro">RIL Interaction</a><br/><div style="padding-left:40px">
10
11<a href="#androidTelephonyRILSolicited">Solicited</a><br/>
12<a href="#androidTelephonyRILUnsolicited">Unsolicited</a><br/></div>
13<a href="#androidTelephonyRILImplementing">Implementing the RIL</a><br/><div style="padding-left:40px">
14
15<a href="#androidTelephonyRILInit">RIL_Init</a><br/></div>
16<a href="#androidTelephonyRILFunctions">RIL Functions</a><br/><div style="padding-left:40px">
17
18<a href="#androidRilFunctionsSolicited">RIL Solicited Command Requests</a><br/>
19<a href="#androidRilFunctionsUnsolicited">RIL Unsolicited Commands</a><br/></div></div></font></div>
20
21<a name="androidTelephonyIntro"></a><h2>Introduction</h2>
22
23<p>Android's Radio Interface Layer (RIL) provides an abstraction layer between Android telephony services (<a href="http://code.google.com/android/reference/android/telephony/package-descr.html">android.telephony</a>) and radio hardware. The RIL is radio agnostic, and includes support for Global System for Mobile communication (GSM)-based radios.&nbsp;</P>
24
25
26<p>The diagram below illustrates the RIL in the context of Android's Telephony system architecture.</p>
27<p><img src="images/telephony.gif"></p>
28
29Solid elements represent Android blocks and dashed elements represent partner-specific blocks.
30
31<p>The RIL consists of two primary components:</p>
32<p><ul>
33<li><b>RIL Daemon</b>: The RIL daemon initializes the Vendor RIL, processes all communication from Android telephony services, and dispatches calls to the Vendor RIL as solicited commands.</li>
34<li><b>Vendor RIL</b>: The radio-specific Vendor RIL of <code>ril.h</code> that processes all communication with radio hardware and dispatches calls to the RIL Daemon (<code>rild</code>) through unsolicited commands.</li>
35</ul>
36</p>
37
38
39<a name="androidTelephonyRILInitialization"></a><h2>RIL Initialization</h2>
40
41<p>Android initializes the telephony stack and the Vendor RIL at startup as described in the sequence below:</p>
42<p><ol>
43<li>RIL daemon reads <code>rild.lib</code> path and <code>rild.libargs</code> system properties to determine the Vendor RIL library to use and any initialization arguments to provide to the Vendor RIL</li>
44<li>RIL daemon loads the Vendor RIL library and calls <code>RIL_Init</code> to initialize the RIL and obtain a reference to RIL functions</li>
45<li>RIL daemon calls <code>RIL_register</code> on the Android telephony stack, providing a reference to the Vendor RIL functions</li></ol>
46</p>
47<p>See the RIL Daemon source code at <code>//device/commands/rild/rild.c</code> for details.</p>
48
49
50<a name="androidTelephonyRILIntro"></a><h2>RIL Interaction</h2>
51
52<p>There are two forms of communication that the RIL handles:</p>
53<ul>
54 <li>Solicited commands: Solicited commands originated by RIL lib, such as <code>DIAL</code> and <code>HANGUP</code>.</li>
55 <li>Unsolicited responses: Unsolicited responses that originate from the baseband, such as <code>CALL_STATE_CHANGED</code> and <code>NEW_SMS</code>.</li>
56</ul>
57
58
59<a name="androidTelephonyRILSolicited"></a><h3>Solicited</h3>
60
61<p>The following snippet illustrates the interface for solicited commands:</p>
62<pre class="prettify">
63void OnRequest (int request_id, void *data, size_t datalen, RIL_Token t);&#13;
64void OnRequestComplete (RIL_Token t, RIL_Error e, void *response, size_t responselen);&#13;
65</pre>
66<p>There are over sixty solicited commands grouped by the following families:</p>
67<p>
68<ul>
69 <li>SIM PIN, IO, and IMSI/IMEI (11)</li>
70 <li>Call status and handling (dial, answer, mute&hellip;) (16)</li>
71 <li>Network status query (4)</li>
72 <li>Network setting (barring, forwarding, selection&hellip;) (12)</li>
73 <li>SMS (3)</li>
74 <li>PDP connection (4)</li>
75 <li>Power and reset (2)</li>
76 <li>Supplementary Services (5)</li>
77 <li>Vendor defined and support (4)<br/>
78 </li>
79</ul>
80</p>
81<p>The following diagram illustrates a solicited call in Android.</p>
82<p><img src="images/telephony_solicted_example.gif"></p>
83
84
85<a name="androidTelephonyRILUnsolicited"></a><h3>Unsolicited</h3>
86
87<p>The following snippet illustrates the interface for unsolicited commands:</p>
88<pre class="prettify">
89void OnUnsolicitedResponse (int unsolResponse, void *data, size_t datalen);
90</pre>
91<p>There are over ten unsolicited commands grouped by the following families:</p>
92<p>
93<ul>
94<li>Network status changed (4)</li>
95<li>New SMS notify (3)</li>
96<li>New USSD notify (2)</li>
97<li>Signal strength or time changed (2)</li>
98</ul>
99</p>
100<p>The following diagram illustrates an unsolicited call in Android.</p>
101<p><img src="images/telephony_unsolicted_example.gif"></p>
102
103
104<a name="androidTelephonyRILImplementing"></a><h2>Implementing the RIL</h2>
105
106<p>To implement a radio-specific RIL, create a shared library that implements a set of functions required by Android to process radio requests. The required functions are defined in the RIL header (<code>/include/telephony/ril.h</code>).</p>
107<p>The Android radio interface is radio-agnostic and the Vendor RIL can use any protocol to communicate with the radio.&nbsp;Android provides a reference Vendor RIL, using the Hayes AT command set, that you can use as a quick start for telephony testing and a guide for commercial vendor RILs. The source code for the reference RIL is found at <code>/commands/reference-ril/</code>.</p>
108<p>Compile your Vendor RIL as a shared library using the convention <code>libril-&lt;companyname&gt;-&lt;RIL version&gt;.so</code>, for example, libril-acme-124.so, where:</p>
109<p><ul>
110<li><b>libril</b>: all vendor RIL implementations start with 'libril'</li>
111<li><b>&lt;companyname&gt;</b>: a company-specific abbreviation</li>
112<li><b>&lt;RIL version&gt;</b>: RIL version number</li>
113<li><b>so</b>: file extension</li>
114</ul>
115</p>
116
117
118<a name="androidTelephonyRILInit"></a><h3>RIL_Init</h3>
119
120<p>Your Vendor RIL must define a RIL_Init function that provides a handle to the functions which will process all radio requests. RIL_Init will be called by the Android RIL Daemon at boot time to initialize the RIL.</p>
121
122<pre class="prettify">
123RIL_RadioFunctions *RIL_Init (RIL_Env* env, int argc, char **argv);
124</pre>
125
126<p>RIL_Init should return a RIL_RadioFunctions structure containing the handles to the radio functions:</p>
127<pre class="prettify">
128type structure {
129 int RIL_version;
130 RIL_RequestFunc onRequest;
131 RIL_RadioStateRequest onStateRequest;
132 RIL_Supports supports;
133 RIL_Cancel onCancel;
134 RIL_GetVersion getVersion;
135}
136RIL_RadioFunctions;
137</pre>
138
139
140<a name="androidTelephonyRILFunctions"></a><h2>RIL Functions</h2>
141
142<p><code>ril.h</code> defines RIL states and variables, such as <code>RIL_UNSOL_STK_CALL_SETUP</code>, <code>RIL_SIM_READY</code>, <code>RIL_SIM_NOT_READY</code>, as well as the functions described in the tables below. Skim the header file (<code>/device/include/telephony/ril.h</code>) for details.</p>
143
144
145<a name="androidRilFunctionsSolicited"></a><h3>RIL Solicited Command Requests</h3>
146
147<p>The vendor RIL must provide the functions described in the table below to handle solicited commands. The RIL solicited command request types are defined in <code>ril.h</code> with the <code>RIL_REQUEST_</code> prefix. Check the header file for details.</p>
148<p><table>
149 <tr><th scope="col">Name</th><th scope="col">Description</th></tr>
150 <tr>
151 <td valign="top"><code> void (*RIL_RequestFunc) (int request, void *data, size_t datalen, RIL_Token t);</code></td>
152 <td valign="top">
153 <p>This is the RIL entry point for solicited commands and must be able to handle the various RIL solicited request types defined in <code>ril.h</code> with the <code>RIL_REQUEST_</code> prefix.</p>
154 <ul>
155 <li><code>request</code> is one of <code>RIL_REQUEST_*</code></li>
156 <li><code>data</code> is pointer to data defined for that <code>RIL_REQUEST_*</code></l>
157 <li><code>t</code> should be used in subsequent call to <code>RIL_onResponse</code></li>
158 <li><code>datalen</code> is owned by caller, and should not be modified or freed by callee</li>
159 </ul>
160 <p>Must be completed with a call to <code>RIL_onRequestComplete()</code>. &nbsp;<code>RIL_onRequestComplete()</code> may be called from any thread before or after this function returns. This will &nbsp;always be called from the same thread, so returning here implies that the radio is ready to process another command (whether or not the previous command has completed).</p></td>
161 </tr>
162 <tr>
163 <td valign="top"><code> RIL_RadioState (*RIL_RadioStateRequest)();</code></td>
164 <td valign="top">This function should return the current radio state synchronously.</td>
165 </tr>
166 <tr>
167 <td valign="top"><code> int (*RIL_Supports)(int requestCode);</code></td>
168 <td valign="top">This function returns "1" if the specified <code>RIL_REQUEST</code> code is supported and 0 if it is not.</td>
169 </tr>
170 <tr>
171 <td valign="top"><code> void (*RIL_Cancel)(RIL_Token t);</code></td>
172 <td valign="top"><p>This function is used to indicate that a pending request should be canceled. This function is called from a separate thread--not the thread that calls <code>RIL_RequestFunc</code>.</p>
173 <p>On cancel, the callee should do its best to abandon the request and call <code>RIL_onRequestComplete</code> with <code>RIL_Errno CANCELLED</code> at some later point.</p>
174 <p>Subsequent calls to <code>RIL_onRequestComplete</code> for this request with other results will be tolerated but ignored (that is, it is valid to ignore the cancellation request).</p>
175 <p><code>RIL_Cancel</code> calls should return immediately and not wait for cancellation.</p></td>
176 </tr>
177 <tr>
178 <td valign="top"><code> const char * (*RIL_GetVersion) (void);</code></td>
179 <td valign="top">Return a version string for your Vendor RIL</td>
180 </tr>
181</table>
182
183
184<p>The vendor RIL uses the following callback methods to communicate back to the Android RIL daemon.</p>
185<p>
186<table>
187 <tr>
188 <th scope="col">Name</th>
189 <th scope="col">Description</th>
190 </tr>
191 <tr>
192 <td><code>void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);</code></td>
193 <td><ul>
194 <li><code>t</code> is parameter passed in on previous call to <code>RIL_Notification</code> routine.</li>
195 <li>If <code>e</code> != SUCCESS, then response can be null and is ignored</li>
196 <li><code>response</code> is owned by caller, and should not be modified or freed by callee</li>
197 <li><code>RIL_onRequestComplete</code> will return as soon as possible</li>
198 </ul></td>
199 </tr>
200 <tr>
201 <td><code>void RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, const struct timeval *relativeTime);</code></td>
202 <td>Call user-specified callback function on the same thread that <code>RIL_RequestFunc</code> is called. If <code>relativeTime</code> is specified, then it specifies a relative time value at which the callback is invoked. If <code>relativeTime</code> is NULL or points to a 0-filled structure, the callback will be invoked as soon as possible.</td>
203 </tr>
204</table></p>
205
206
207<a name="androidRilFunctionsUnsolicited"></a><h3>RIL Unsolicited Commands</h3>
208
209<p>The functions listed in the table below are call-back functions used by the Vendor RIL to invoke unsolicited commands on the Android platform. See <code>ril.h</code> for details. </p>
210<p>
211<table>
212 <tr>
213 <th scope="col">Name</th>
214 <th scope="col">Description</th>
215 </tr>
216 <tr>
217 <td><code>void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, size_t datalen);</code></td>
218 <td><ul>
219 <li><code>unsolResponse</code> is one of <code>RIL_UNSOL_RESPONSE_*</code></li>
220 <li><code>data</code> is pointer to data defined for that <code>RIL_UNSOL_RESPONSE_*</code></li>
221 <li><code>data</code> is owned by caller, and should not be modified or freed by callee</li>
222 </ul></td>
223 </tr>
224</table></p>