Android RIL Radio Layer Interface

合集下载

Android中RIL层详细分析

Android中RIL层详细分析

介绍本文档对Android RIL部分的内容进行了介绍,其重点放在了Android RIL的原生代码部分。

包括四个主题:RIL框架介绍RIL与WindowsMobile RILRIL portingRIL的java框架在本文档中将Android代码中的重要模块列出进行分析,并给出了相关的程序执行流程介绍,以加深对模块间交互方式的理解。

对于java代码部分,这里仅进行简单的介绍。

如果需要深入了解,可以查看相关参考资料。

本文档中还对Android RIL的Porting部分内容进行了描述和分析。

针对对unix操作系统环境并不熟悉的读者,本文档中所涉及到的相关知识包括: Unix file systemUnix socketUnix threadUnix 下I/O多路转接以上信息可以在任意一份描述Unix系统调用的文档中找到。

RIL框架介绍术语:fd Linux文件描述符pipe Linux管道cond 一般是conditionvariable的缩写tty 通常使用tty来简称各种类型的终端设备unsolicited response 被动请求命令来自basebandevent loop android的消息队列机制,由Linux 的系统调用select()实现init守护进程启动后被执行的启动脚本。

HAL 硬件抽象层(Hardware Abstraction Layer,HAL)Android RIL概况Android RIL提供了无线硬件设备与电话服务之间的抽象层。

下图展示了RIL在Android 体系中的位置。

android的ril位于应用程序框架与内核之间,分成了两个部分,一个部分是rild,它负责socket与应用程序框架进行通信。

另外一个部分是Vendor RIL,这个部分负责向下是通过两种方式与radio进行通信,它们是直接与radio通信的AT指令通道和用于传输包数据的通道,数据通道用于手机的上网功能。

Android软件流程之App&&Framework&&Ril

Android软件流程之App&&Framework&&Ril

Android软件流程之App&&Framework&&Ril(待续)前言本人主要负责Android的Phone模块的bug修改,经过几个月的学习,熟悉了Phone 模块ARM11(App、Framework与Ril)的整体框架。

本文我将带领大家熟悉Android的App层与Framework层与Ril层如何进行交互,让大家了解具体代码流程,了解体系的整体框架。

下面我将首先介绍App层、Framework层的详细流程,之后是Ril层。

在看本文之前希望读者能对一下知识有所了解,特别是Android的Handler机制,当然在文章中我也会对下面知识加以简单介绍。

➢面向对象编程思想➢设计模式➢Android的Handle ,Message ,Looper 机制第一部分Android软件流程之App&&Framework一. 简述1.Ril概述RIL(Radio Interface Layer)工作在Android的Framework层之下,主要有c语言编写,还有一部分c++,它主要负责数据的可靠传输、上层命令的发送以及response的解析。

当然,除了对网络的支持,RIL也支持SMS、Call等功能。

当然这么说还是很抽象,下面我们就来看看Ril和上层进行交互的所有“消息”。

2.Ril和上层进行交互的“信息”这里我所谓的“消息”,其实可以概括为二种:✓Request:上层,也就是App层和Framework层下发给Ril层的一些请求(如打电话RIL_REQUEST_DIAL, 获取SIM卡的状态RIL_REQUEST_GET_SIM_STATUS等),最终由Ril层把这些请求下发给ARM9侧。

✓Response:Response代表ARM9侧向ARM11侧上报的一些信息,它又可以分为两种✧UNSOL_RESPONSE:主动上报的一些信息,如来短信,✧SOL_RESPONSE:上层下发的一些请求,是需要有应答的,也可以说是响应的,如我下发了RIL_REQUEST_GET_SIM_STATUS,需要Ril上报回来SIM_STATUS,我们把这些上报信息称为命令的响应。

通信中的拉姆架构

通信中的拉姆架构

通信中的拉姆架构
Android电话部分主要分为:Modem驱动、RIL(Radio Interface Layer)、电话服务框架、应用4层结构。

通讯框架的应用层主要包括通话界面IncallUi,处理通话逻辑的TeleService和Telecomm,网络设置ConnectivitySettings等。

TeleService和Telecomm通过Binder传递数据。

Framework层是通信框架的核心部分,也是本书介绍的重点。

包括通话,数据网络,短彩信收发,主副卡切换等业务逻辑。

这在之后的章节中会为大家一一介绍。

rild是Init进程启动的一个本地服务,这里需要注意的是,从Google8.0之后,这个本地服务的通讯方式从socket改为了HIDL。

HIDL是用于指定HAL与其用户之间接口的一个接口描述语言(Interface Description Language),它允许将指定的类型与函数调用收集到接口(Interface)和包(Package)中。

更广泛地说,HIDL 是一个可以让那些独立编译的代码库(Libraries)之间进行通信的系统。

Google在考虑了互用,效率,直观这几各方面才决定将通讯方式改为HIDL。

Android RIL 分析

Android RIL 分析

RIL的Request流程(4)
onRequest方法会通过传入的请求类型来调用指定的
request×××()方法,该方法则负责组装AT指令并下 发给at_send_command()方法集合中的一个,这个方 法集合提供了针对不同类型AT指令的实现,如单行AT 指令at_send_command_singleline(),短信息指令 at_send_command_sms()等。 最后,执行at_send_command_full(),再通过一个互斥 的at_send_command_full_nolock()调用,完成最终的 写出操作,在writeline()中,写出到初始化时打开的设备 中。
SMS在RIL中的处理流程1
应用中使用android.telephony.smsManager类的
sendTextMessage()方法发送sms smsManager类通过AIDL接口(注1)与Java Framework 中的 com.android.internal.telephony.IccSmsInterfaceMana ger通信 IccSmsInterfaceManager最终通过 com.android.internal.telephony.ril,将sms数据与 RIL_REQUEST_SEND_SMS消息,通过JNI接口(注2) 下发到RIL的C/C++实现部份中去。
ห้องสมุดไป่ตู้
普通上报的Response处理
IsFinalResponse()和isFinalResponseError()所处理的是一条AT指令的
RIL的Response流程
AT的response有两种,一种是unsolicited。另一种是普通

STK

STK
Android RIL& STK Sharing
( Radio Interface Layer &SIM Tool Kit)
2015-1-22
Android 系统框架
2015-1-22
Android 电话模块框架
2015-1-22
电话模块数据流
2015-1-22
RIL
• RIL(Radio Interface Layer,无线通信接口层),在Android中的 实现源代码可以分为两大部分 *Framework框架层中的Java相关程序,简称RILJ。 *HAL层中的C/C++程序,简称RILC (包括RILD) • RIL层做两件事情: 向串口发送AT命令, 接收串口对AT命令的 处理结果. AT为Attention简写. At命令可理解为向底层发送 的特定目的的命令. • 手机框架需要适应多类型的Modem接入到系统中,而对于 不同的Modem有不同的特性,AT指令的格式或者回应有所 不同,但是这种特性在设计应用时不可能完全考虑和兼容。 所以设计者在设计电话系统时,建立了一个虚拟电话系统, 为该虚拟电话系统规定了标准的功能,上层的电话管理都 是建立在这些标准的功能基础之上。而RIL则是将虚拟电话 系统的标准功能转换成实际的所使用的Modem的AT指令
2015-1-22
2015-1-22
AppInterface.java
• AppInterface 是一个 接口,主要用于 Stk应用和 stk telephony 之间的通 信。 • AppInterface 定义了stk应用里的命令。 public static enum CommandType{ DISPLAY_TEXT(0x21), GET_INKEY(0x22), GET_INPUT(0x23), LAUNCH_BROWSER(0x15), PLAY_TONE(0x20), REFRESH(0x01), SELECT_ITEM(0x24), SEND_SS(0x11), SEND_USSD(0x12), SEND_SMS(0x13), SEND_DTMF(0x14), SET_UP_EVENT_LIST(0x05), SET_UP_MENU(0x25), SET_UP_IDLE_MODE_TEXT(0x28), SET_UP_CALL(0x10), PROVIDE_LOCAL_INFORMATION(0x26), OPEN_CHANNEL(0x40), LANGUAGE_NOTIFICATION(0x35), CLOSE_CHANNEL(0x41), RECEIVE_DATA(0x42), SEND_DATA(0x43), GET_CHANNEL_STATUS(0x44), ACTIVATE(0x70);

单编qcril的指令 -回复

单编qcril的指令 -回复

单编qcril的指令-回复QCRIL (Qualcomm Cellular Radio Interface Layer) 是Qualcomm公司开发的一套用于通信模块的指令集。

它作为Android平台上的一个模块,用于管理与基带芯片之间的通信,以及处理与基站的交互。

下面一步一步回答关于单编QCRIL指令的问题。

第一步:了解QCRIL指令的概念和功能QCRIL指令是指使用QMI (Qualcomm Modem Interface) 协议进行通信的指令集。

它可以用于对LTE、WCDMA、CDMA等移动通信技术进行控制和管理。

通过QCRIL指令,开发人员能够实现通信模块的各种功能,例如发送短信、拨打电话、建立数据连接等。

第二步:QCRIL指令的使用场景和优势QCRIL指令可以广泛应用于Android平台上的移动设备以及物联网设备中。

它能够与基带芯片进行高效的通信,并实现对网络和通信功能的控制。

QCRIL指令的优势包括:1. 灵活性:QCRIL指令可以根据不同的需求进行定制和扩展,满足不同设备和应用场景的要求。

2. 高可靠性:QCRIL指令在与基带芯片之间的通信中采用了可靠的QMI 协议,确保数据的可靠传输和处理。

3. 良好的兼容性:QCRIL指令可以与不同版本的Android系统以及Qualcomm芯片进行兼容,为开发人员提供更大的灵活性和选择性。

第三步:QCRIL指令的基本用法和常见指令QCRIL指令可以通过Android平台上的RIL (Radio Interface Layer)来调用和执行。

常见的QCRIL指令包括:1. RIL_REQUEST_GET_SIM_STATUS:获取SIM卡的状态信息。

2. RIL_REQUEST_DIAL:拨打电话。

3. RIL_REQUEST_SEND_SMS:发送短信。

4. RIL_REQUEST_SETUP_DATA_CALL:建立数据连接。

5. RIL_REQUEST_GET_CURRENT_CALLS:获取当前通话状态。

Android_RIL层剖析(一家网站上找的)

/android_pdk/telephony.html这个上的是文还有英文Android 无线接口层(Radio Layer Interface)目录:1、介绍2、RIL 初始化3、RIL 交互----3.1 主动请求----3.2 被动请求4、实现RIL-----RIL初始化5、RIL函数----5.1 RIL 主动命令请求----5.2 RIL 被动请求的命令1 介绍Android的无线接口层(RIL)提供了Android服务(android.telephony)与无线电硬件之间的抽象层。

RIL是通讯无关的,提供基于GSM的网络支持。

下图显示了RIL位于Android系统架构中的位置。

图1实线框表示Android部分,虚线框表示合作伙伴所专用的部分。

RIL包含两个基本部件:RIL守护进程(RIL Daemon):RIL守护进程初始化Vendor RIL,管理所有来自Android通讯服务的通讯,将其作为被请求的命令(solicited commands)调度给Vendor RIL。

Vendor RIL:ril.h文件中的无线电专用Vendor RIL掌管着所有和无线电硬件的通讯,并且通过未被请求的命令(unsolicited commands)分发给RIL 守护进程。

2 RIL 初始化Android在启动时初始化通讯栈和Vendor RIL,描述如下:1. RIL守护进程读取rild.lib路径和rild.libargs系统参数,决定应该使用的Vendor RIL库和向Vendor RIL提供的初始化参数2. RIL守护进程加载Vendor RIL库,执行RIL_Init初始化RIL并为RIL函数获取参数。

3. RIL守护进程调用Android通讯栈中RIL_register,为Vendor RIL函数提供参考。

RIL守护进程源码请参考//device/commands/rild/rild.c3 RIL 交互RIL句柄提供了两种交互方式:主动请求命令(Solicited commands):主动请求命令来自RIL lib,比如DIAL 和HANGUP。

Android 无线接口层(RIL) 概述


read loop
Read loop是解决的问题是:解析从Modem发 过来的回应。 如果遇到URC则通过handleUnsolicited上报的 RIL_JAVA。 如果是命令的应答,则通过 handleFinalResponse通知send_at_command 有应答结果。
RIL 交互
RIL句柄提供了两种交互方式:
被动请求
void OnUnsolicitedResponse (int unsolResponse, void *data, size_t datalen); 有超过10条被动请求命令: * 网络状态改变(4) * 新短信通知(3) * 新USSD通知(2) * 信号强度和时间改变(2)
loop示意图 read loop示意图
EVENT对象 EVENT对象
struct ril_event { struct ril_event *next; struct ril_event *prev; int fd;(事件相关设备句柄。例如对于串口数据事件, fd就是相关串口的设备句柄) int index; bool persist;(如果是保持的,则不从watch_list中删 除) struct timeval timeout; ril_event_cb func;(回调事件处理函数) void *param;(回调时参数) };
Sender
异步应答框架
异步应答来讲,命令的发起者发送后,并不等 待应答就返回,应答的回应是异步的,处理结 果通过消息的方式返回 在源代码中RILRequest的mSerail就用作了 Token。Token用来唯一标识每次发送的请求, 并且Token将被传递到RILD,RILD在组装应答 是将Token写入,并传回到ril-java,ril-java根据 该Token找到相应的Request对象。

正确了解ROM,基带,以及RIL


因为LG不容易变砖,不同系统不同基带不同国家的,都有自己最理想的配合。刷了其它ROM都不知道自己的RIL是什么版本。而一般分享ROM的楼主也没有放出补丁。
实例: 现在MIUI中国测试版本的RIL 是匹配最早期218基带,但是刷它的用户可能是使用欧版本最新的622基带。这样就会做成问题。
因此,我介绍一个很小的应用程序,它会显示您目前已安装LGE-ril.so 的个版本
请检查你目前使用的基带: 设置-关于手机-基带版本。
RIL(无线接口层)
手机软件结构分为两个基本层面:基带(baseband)和应用(application)。在其中间的主要连接桥梁就是RIL。 为了连接基带的应用,并允许蜂窝手机网络和用户界面之间的通信,就是RIL的一个逻辑层使用。 这一层中存在的最现代化的移动操作系统架构,需要操作系统和使用的基带芯片之间的紧密集成。在Android的管理是使用RIL守护进程,来连接到供应商的基带。基带的开发和修改是由供应商或手机厂商本身。
一、正确了解ROM,基带,以及RIL。
1)、ROM
对于android手机来说,在刷机这个问题上所指的ROM,即是操作系统,XX版本的ROM,就是XX版本的系统。比如Windows XP系统,微软官方的称呼就是XP,如果该XP是卖到某某地区的定制XP,就被称呼为XX版XP。我们的ROM,也是类似这个概念的。
因为RIL提供了语音、数据、SMS短信、SIM卡管理以及STK应用的功能,所以不适当的RIL,可以做成“漏接”和“假死”。 (当然“漏接”和“假死”,不单是因为不适当的RIL。)
因为很多实践证明目前大多数RIL驱动“假死”问题,都是由于软件问题而非硬件问题造成的。实际上,系统上出现这种问题也不是很奇怪的,因为出现“假死”的原因主要是因为RIL驱动程序的入口点函数、注册键和GSM模块没有进行适当的交互。因为RIL驱动程序写得是否很好是因人而异的, 毕竟RIL驱动层是用户自己定制的, 而非由Andorid实现的。

Android - Porting Guide_RIL

Radio Layer InterfaceIntroductionRIL InitializationRIL InteractionSolicitedUnsolicitedImplementing the RILRIL_InitRIL FunctionsRIL Solicited Command RequestsRIL Unsolicited CommandsIntroductionAndroid's Radio Interface Layer (RIL) provides an abstraction layer between Android telephony services (android.telephony) and radio hardware. The RIL is radio agnostic, and includes support for Global System for Mobile communication (GSM)-based radios.The diagram below illustrates the RIL in the context of Android's Telephony system architecture.Solid elements represent Android blocks and dashed elements represent partner-specific proprietary blocks.The RIL consists of two primary components:•RIL Daemon: The RIL daemon initializes the Vendor RIL, processes all communication from Android telephony services, and dispatches calls to the Vendor RIL as solicited commands.•Vendor RIL: The radio-specific Vendor RIL of ril.h that processes all communication with radio hardware and dispatches calls to the RILDaemon (rild) through unsolicited commands.RIL InitializationAndroid initializes the telephony stack and the Vendor RIL at startup as described in the sequence below:1. RIL daemon reads rild.lib path and rild.libargs system propertiesto determine the Vendor RIL library to use and any initializationarguments to provide to the Vendor RIL2. RIL daemon loads the Vendor RIL library and calls RIL_Init to initializethe RIL and obtain a reference to RIL functions3. RIL daemon calls RIL_register on the Android telephony stack,providing a reference to the Vendor RIL functionsSee the RIL Daemon source code at //device/commands/rild/rild.c for details.RIL InteractionThere are two forms of communication that the RIL handles:•Solicited commands: Solicited commands originated by RIL lib, such as DIAL and HANGUP.•Unsolicited responses: Unsolicited responses that originate from the baseband, such as CALL_STATE_CHANGED and NEW_SMS.SolicitedThe following snippet illustrates the interface for solicited commands:void OnRequest (int request_id, void *data, size_t datalen, RIL_Token t);void OnRequestComplete (RIL_Token t, RIL_Error e, void *response, size_t responselen);There are over sixty solicited commands grouped by the following families: •SIM PIN, IO, and IMSI/IMEI (11)•Call status and handling (dial, answer, mute…) (16)•Network status query (4)•Network setting (barring, forwarding, selection…) (12)•SMS (3)•PDP connection (4)•Power and reset (2)•Supplementary Services (5)•Vendor defined and support (4)The following diagram illustrates a solicited call in Android.UnsolicitedThe following snippet illustrates the interface for unsolicited commands:void OnUnsolicitedResponse (int unsolResponse, void *data, size_t datalen);There are over ten unsolicited commands grouped by the following families: •Network status changed (4)•New SMS notify (3)•New USSD notify (2)•Signal strength or time changed (2)The following diagram illustrates an unsolicited call in Android.Implementing the RILTo 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 (/include/telephony/ril.h).The Android radio interface is radio-agnostic and the Vendor RIL can use any protocol to communicate with the radio. 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 /commands/reference-ril/.Compile your Vendor RIL as a shared library using theconvention libril-<companyname>-<RIL version>.so, for example,libril-acme-124.so, where:•libril: all vendor RIL implementations start with 'libril'•<companyname>: a company-specific abbreviation•<RIL version>: RIL version number•so: file extensionRIL_InitYour 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.RIL_RadioFunctions *RIL_Init (RIL_Env* env, int argc, char **argv);RIL_Init should return a RIL_RadioFunctions structure containing the handles to the radio functions:type structure {intRIL_version;RIL_RequestFunconRequest;RIL_RadioStateRequest onStateRequest;RIL_Supportssupports;RIL_CancelonCancel;RIL_GetVersiongetVersion;}RIL_RadioFunctions;RIL Functionsril.h defines RIL states and variables, suchas RIL_UNSOL_STK_CALL_SETUP, RIL_SIM_READY, RIL_SIM_NOT_READY, as well as the functions described in the tables below. Skim the header file(/device/include/telephony/ril.h) for details.RIL Solicited Command RequestsThe vendor RIL must provide the functions described in the table below to handle solicited commands. The RIL solicited command request types are defined in ril.h with the RIL_REQUEST_ prefix. Check the header file for details.Name Descriptionvoid(*RIL_RequestFunc) (int request, void*data, size_t datalen, RIL_Token t);This is the RIL entry point for solicited commands and must be able to handle the various RIL solicited request types definedin ril.h with the RIL_REQUEST_ prefix.•request is one of RIL_REQUEST_*•data is pointer to data defined for that RIL_REQUEST_*•t should be used in subsequent call to RIL_onResponse•datalen is owned by caller, and should not be modified or freed by calleeMust be completed with a callto RIL_onRequestComplete(). RIL_onRequestCom plete() may be called from any thread before or after this function returns. This will 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).RIL_RadioState(*RIL_RadioStateReque st)();This function should return the current radio state synchronously.int(*RIL_Supports)(int requestCode);This function returns "1" if thespecified RIL_REQUEST code is supported and 0 if it is not.void(*RIL_Cancel)(RIL_Tok en t);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 RIL_RequestFunc.On cancel, the callee should do its best to abandon the request andcall RIL_onRequestComplete with RIL_Errno CANCELLED at some later point.Subsequent calls to RIL_onRequestComplete for this request with other results will be tolerated but ignored (that is, it is valid to ignore the cancellation request).RIL_Cancel calls should return immediately and not wait for cancellation.const char *(*RIL_GetVersion)(void);Return a version string for your Vendor RILThe vendor RIL uses the following callback methods to communicate back to the Android RIL daemon.Name DescriptionvoidRIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, •t is parameter passed in on previous callto RIL_Notification routine.size_t responselen);•If e != SUCCESS, then responsecan be null and is ignored•response is owned by caller,and should not be modified orfreed by callee•RIL_onRequestComplete willreturn as soon as possiblevoid RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, const struct timeval*relativeTime);Call user-specified callback function on the same threadthat RIL_RequestFunc is called.If relativeTime is specified, then it specifies a relative time value at which the callback is invoked.If relativeTime is NULL or points to a 0-filled structure, the callback will be invoked as soon as possible.RIL Unsolicited CommandsThe functions listed in the table below are call-back functions used by the Vendor RIL to invoke unsolicited commands on the Android platform. See ril.h for details.Name Descriptionvoid RIL_onUnsolicitedResponse(int unsolResponse, const void *data, size_t datalen);•unsolResponse is oneof RIL_UNSOL_RESPONSE_*•data is pointer to data defined forthat RIL_UNSOL_RESPONSE_*•data is owned by caller, and should not be modified or freed by callee。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档