• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Radio Layer Interface
2pdk.version=1.0
3doc.type=porting
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8<h2>In this document</h2>
9<a name="toc"/>
10<ul>
11<li><a href="#androidTelephonyRILInitialization">RIL Initialization</a></li>
12<li><a href="#androidTelephonyRILIntro">RIL Interaction</a></li>
13<li><a href="#androidTelephonyRILImplementing">Implementing the RIL</a></li>
14<li><a href="#androidTelephonyRILFunctions">RIL Functions</a></li>
15</ul>
16</div>
17</div>
18
19<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>
20
21
22<p>The diagram below illustrates the RIL in the context of Android's Telephony system architecture.</p>
23<p><img src="images/telephony.gif"></p>
24
25Solid elements represent Android blocks and dashed elements represent partner-specific blocks.
26
27<p>The RIL consists of two primary components:</p>
28<p><ul>
29<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>
30<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>
31</ul>
32</p>
33
34
35<a name="androidTelephonyRILInitialization"></a><h3>RIL Initialization</h3>
36
37<p>Android initializes the telephony stack and the Vendor RIL at startup as described in the sequence below:</p>
38<p><ol>
39<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>
40<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>
41<li>RIL daemon calls <code>RIL_register</code> on the Android telephony stack, providing a reference to the Vendor RIL functions</li></ol>
42</p>
43<p>See the RIL Daemon source code at <code>//device/commands/rild/rild.c</code> for details.</p>
44<p><b>System Properties</b></p>
45<p>The following RIL-related system properties are set by the RIL library:</p>
46<p><ul>
47<li><code>ro.ril.ecclist</code>: list of valid Emergency Call Codes, for example, 911. Values are read from <code>EF_ECC</code> on the SIM and possibly supplmented by tables based on operator, network, or manufacturing code.</li></ul></p>
48
49<p>The following RIL_related system properties are available to the RIL library:</p>
50<p><ul>
51<li><code>ro.ril.hsxpa</code>: inidcates <code>hsxpa</code> support of target network.</li>
52<li><code>ro.ril.gprsclass</code>: inidcates GPRS class of target network.</li>
53<li><code>ro.ril.enable.3g.prefix=1</code>: adds the 3G prefix to the operator name.</li>
54</ul></p>
55
56<a name="androidTelephonyRILIntro"></a><h3>RIL Interaction</h3>
57
58<p>There are two forms of communication that the RIL handles:</p>
59<ul>
60  <li>Solicited commands: Solicited commands originated by RIL lib, such as <code>DIAL</code> and <code>HANGUP</code>.</li>
61  <li>Unsolicited responses: Unsolicited responses that originate from the baseband, such as <code>CALL_STATE_CHANGED</code> and <code>NEW_SMS</code>.</li>
62</ul>
63
64
65<a name="androidTelephonyRILSolicited"></a><h4>Solicited</h4>
66
67<p>The following snippet illustrates the interface for solicited commands:</p>
68<pre class="prettify">
69void OnRequest (int request_id, void *data, size_t datalen, RIL_Token t);&#13;
70void OnRequestComplete (RIL_Token t, RIL_Error e, void *response, size_t responselen);&#13;
71</pre>
72<p>There are over sixty solicited commands grouped by the following families:</p>
73<p>
74<ul>
75  <li>SIM PIN, IO, and IMSI/IMEI (11)</li>
76  <li>Call status and handling (dial, answer, mute&hellip;) (16)</li>
77  <li>Network status query (4)</li>
78  <li>Network setting (barring, forwarding, selection&hellip;) (12)</li>
79  <li>SMS (3)</li>
80  <li>PDP connection (4)</li>
81  <li>Power and reset (2)</li>
82  <li>Supplementary Services (5)</li>
83  <li>Vendor defined and support (4)<br/>
84                    </li>
85</ul>
86</p>
87<p>The following diagram illustrates a solicited call in Android.</p>
88<p><img src="images/telephony_solicted_example.gif"></p>
89
90
91<a name="androidTelephonyRILUnsolicited"></a><h4>Unsolicited</h4>
92
93<p>The following snippet illustrates the interface for unsolicited commands:</p>
94<pre class="prettify">
95void OnUnsolicitedResponse (int unsolResponse, void *data, size_t datalen);
96</pre>
97<p>There are over ten unsolicited commands grouped by the following families:</p>
98<p>
99<ul>
100<li>Network status changed (4)</li>
101<li>New SMS notify (3)</li>
102<li>New USSD notify (2)</li>
103<li>Signal strength or time changed (2)</li>
104</ul>
105</p>
106<p>The following diagram illustrates an unsolicited call in Android.</p>
107<p><img src="images/telephony_unsolicted_example.gif"></p>
108
109
110<a name="androidTelephonyRILImplementing"></a><h3>Implementing the RIL</h3>
111
112<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>
113<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>
114<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>
115<p><ul>
116<li><b>libril</b>: all vendor RIL implementations start with 'libril'</li>
117<li><b>&lt;companyname&gt;</b>: a company-specific abbreviation</li>
118<li><b>&lt;RIL version&gt;</b>: RIL version number</li>
119<li><b>so</b>: file extension</li>
120</ul>
121</p>
122
123
124<a name="androidTelephonyRILInit"></a><h4>RIL_Init</h4>
125
126<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>
127
128<pre class="prettify">
129RIL_RadioFunctions *RIL_Init (RIL_Env* env, int argc, char **argv);
130</pre>
131
132<p>RIL_Init should return a RIL_RadioFunctions structure containing the handles to the radio functions:</p>
133<pre class="prettify">
134type structure {
135	int RIL_version;
136	RIL_RequestFunc onRequest;
137	RIL_RadioStateRequest onStateRequest;
138	RIL_Supports supports;
139	RIL_Cancel onCancel;
140	RIL_GetVersion getVersion;
141}
142RIL_RadioFunctions;
143</pre>
144
145
146<a name="androidTelephonyRILFunctions"></a><h3>RIL Functions</h3>
147
148<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>
149
150
151<a name="androidRilFunctionsSolicited"></a><h4>RIL Solicited Command Requests</h4>
152
153<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>
154<p><table>
155  <tr><th scope="col">Name</th><th scope="col">Description</th></tr>
156  <tr>
157    <td valign="top"><code> void (*RIL_RequestFunc) (int request, void *data, size_t datalen, RIL_Token t);</code></td>
158    <td valign="top">
159	<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>
160	<ul>
161        <li><code>request</code> is one of <code>RIL_REQUEST_*</code></li>
162        <li><code>data</code> is pointer to data defined for that <code>RIL_REQUEST_*</code></l>
163        <li><code>t</code> should be used in subsequent call to <code>RIL_onResponse</code></li>
164        <li><code>datalen</code> is owned by caller, and should not be modified or freed by callee</li>
165      </ul>
166	<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>
167  </tr>
168  <tr>
169    <td valign="top"><code> RIL_RadioState (*RIL_RadioStateRequest)();</code></td>
170    <td valign="top">This function should return the current radio state synchronously.</td>
171  </tr>
172  <tr>
173    <td valign="top"><code> int (*RIL_Supports)(int requestCode);</code></td>
174    <td valign="top">This function returns "1" if the specified <code>RIL_REQUEST</code> code is supported and 0 if it is not.</td>
175  </tr>
176  <tr>
177    <td valign="top"><code> void (*RIL_Cancel)(RIL_Token t);</code></td>
178    <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>
179      <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>
180      <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>
181    <p><code>RIL_Cancel</code> calls should return immediately and not wait for cancellation.</p></td>
182  </tr>
183  <tr>
184    <td valign="top"><code> const char * (*RIL_GetVersion) (void);</code></td>
185    <td valign="top">Return a version string for your Vendor RIL</td>
186  </tr>
187</table>
188
189
190<p>The vendor RIL uses the following callback methods to communicate back to the Android RIL daemon.</p>
191<p>
192<table>
193  <tr>
194    <th scope="col">Name</th>
195    <th scope="col">Description</th>
196  </tr>
197  <tr>
198    <td><code>void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);</code></td>
199    <td><ul>
200      <li><code>t</code> is parameter passed in on previous call to <code>RIL_Notification</code> routine.</li>
201      <li>If <code>e</code> != SUCCESS, then response can be null and is ignored</li>
202      <li><code>response</code> is owned by caller, and should not be modified or freed by callee</li>
203      <li><code>RIL_onRequestComplete</code> will return as soon as possible</li>
204    </ul></td>
205  </tr>
206  <tr>
207    <td><code>void RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, const struct timeval *relativeTime);</code></td>
208    <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>
209  </tr>
210</table></p>
211
212
213<a name="androidRilFunctionsUnsolicited"></a><h4>RIL Unsolicited Commands</h4>
214
215<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>
216<p>
217<table>
218  <tr>
219    <th scope="col">Name</th>
220    <th scope="col">Description</th>
221  </tr>
222  <tr>
223    <td><code>void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, size_t datalen);</code></td>
224    <td><ul>
225      <li><code>unsolResponse</code> is one of <code>RIL_UNSOL_RESPONSE_*</code></li>
226      <li><code>data</code> is pointer to data defined for that <code>RIL_UNSOL_RESPONSE_*</code></li>
227      <li><code>data</code> is owned by caller, and should not be modified or freed by callee</li>
228    </ul></td>
229  </tr>
230</table></p>
231