• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Ril
2
3## Overview
4
5The Ril driver developed based on the Hardware Driver Foundation (HDF) driver framework shields hardware differences and provides APIs for upper-layer services, such as making calls, sending SMS messages, and activating SIM cards.
6
7The Ril driver module contains definitions and implementation code of Ril hardware driver interfaces (HDIs) and provides the telephony driver capability APIs for the upper layer. The HDIs implement service processing related to the following services:
8
9-   Call
10-   SIM card
11-   SMS/MMS
12-   Radio
13-   Cellular data
14
15**Figure 1** Architecture of the Ril driver module
16
17![Ril driver module](figures/ril-driver-module-architecture.png)
18
19## Directory Structure
20
21The source code directory structure is as follows:
22
23```
24/drivers/peripheral/ril
25├── figures                # Readme resource files
26├── interfaces             # Driver capability APIs provided for upper-layer services
27│   └── include            # APIs exposed externally
28```
29
30## **Constraints**
31
32-   Programming language: C++
33-   Software constraints: This module must work with the Ril Adapter module (ril\_adapter).
34-   Hardware constraints: The device must be equipped with a modem capable of independent cellular communication.
35
36## Usage Description
37
38### Available APIs
39
40The Ril driver provides capability APIs that can be directly called by the framework layer. The main functions are as follows: call, SIM card, SMS/MMS, cellular data, and event reporting. The following table lists the APIs provided by the Ril driver module.
41
42**Table 1** Ril HDI APIs
43
44| API                                                      | Description                                                    |
45| ------------------------------------------------------------ | ------------------------------------------------------------ |
46| int32_t SetCallback(const sptr\<IRilCallback\> &rilCallback) | Sets the IRil callback.|
47| int32_t Dial(int32_t slotId, int32_t serialId, const DialInfo &dialInfo) | Makes a call. **slotId** indicates the card slot ID, **serialId** indicates the serial ID of the request, and **dialInfo** indicates the dialing information.|
48| int32_t Answer(int32_t slotId, int32_t serialId) | Answers a call. **slotId** indicates the card slot ID, and **serialId** indicates the serial ID of the request.|
49| int32_t SendGsmSms(int32_t slotId, int32_t serialId, const GsmSmsMessageInfo &gsmSmsMessageInfo) | Sends a GSM SMS message. **slotId** indicates the card slot ID, **serialId** indicates the serial ID of the request, and **gsmSmsMessageInfo** indicates the GSM SMS message information.|
50| int32_t SetActiveSim(int32_t slotId, int32_t serialId, int32_t index, int32_t enable) |  Activates or deactivates a SIM card. **slotId** indicates the card slot ID, **serialId** indicates the serial ID of the request, **index** indicates the index value of the SIM card information, and **enable** indicates the activation status.|
51| int32_t GetOperatorInfo(int32_t slotId, int32_t serialId) | Queries the carrier name. **slotId** indicates the card slot ID, and **serialId** indicates the serial ID of the request.|
52| int32_t ActivatePdpContext(int32_t slotId, int32_t serialId, const DataCallInfo &dataCallInfo) | Activates the PDP context. **slotId** indicates the card slot ID, and **dataCallInfo** indicates the data service information.|
53| int32_t SetRadioState(int32_t slotId, int32_t serialId, int32_t fun, int32_t rst) | Sets the radio state. **slotId** indicates the card slot ID, **serialId** indicates the serial ID of the request, **fun** indicates the function mode, and **rst** indicates whether to perform a reset.|
54
55For details about the APIs, access [drivers_interface_ril](https://gitee.com/openharmony/drivers_interface/blob/master/ril/v1_1/IRil.idl).
56
57### How to Use
58
59This section uses the call service implementation as an example.
60
61Sample code:
62
63```c++
64#include "V1_1/iril.h"
65
66/* Ril callback class */
67class RilCallback : public HDI::Ril::V1_1::IRilCallback {
68    int32_t DialResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo) override;
69    int32_t HangupResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo) override;
70    int32_t RejectResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo) override;
71    int32_t AnswerResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo) override;
72    ...
73}
74
75/* Callback */
76int32_t RilCallback::DialResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
77{
78    printf("DialResponse");
79    return 0;
80}
81
82void RilSample(void)
83{
84    /* Create a Ril interface instance. */
85    sptr<OHOS::HDI::Ril::V1_1::IRil> g_rilInterface = OHOS::HDI::Ril::V1_1::IRil::Get();
86    if (g_rilInterface == nullptr) {
87        return;
88    }
89    /* Set a callback. */
90    sptr<HDI::Ril::V1_1::IRilCallback> g_cbObj = new RilCallback();
91    g_rilInterface->SetCallback(RilCallback());
92
93    /** Make a call. **/
94    int32_t slotId = 0;
95    int32_t serialId = 1;
96    HDI::Ril::V1_1::DialInfo dialInfo = {};
97    dialInfo.address = "10086";
98    dialInfo.clir = 0;
99    int32_t ret = g_rilInterface->Dial(slotId, serialId, dialInfo);
100}
101```
102
103## Repositories Involved
104
105[Driver](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md)
106
107[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
108
109[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
110
111[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
112
113[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral)
114
115[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md)
116
117[telephony\_ril\_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README.md)
118