Compare commits

..

74 Commits
dev ... trunk

Author SHA1 Message Date
v-tangmeng 74ac7b0ef2 update release note
Signed-off-by: v-tangmeng <v-tangmeng@xiaomi.com>
2026-05-14 20:56:55 +08:00
tangmeng c1943f8c68 docs: add trunk-5.5 release notes (en & zh-cn)
- Add en/release_notes/v5.5.md and zh-cn/release_notes/v5.5.md
- Cover kernel / bluetooth / connectivity / multimedia / graphics /
  system services / security / QuickApp / AI Agent new features,
  breaking changes and upgrade guide
- Link both versions from top-level README.md and README_zh-cn.md
2026-05-11 13:58:23 +08:00
zhangxiaowei16 53e6d1a679 docs: remove macOS quick start guide and related FAQ
openvela does not currently support macOS as a build host.
Remove macOS quick start documents (zh-cn and en) and the
related FAQ entry (#16) about macOS simulator issues.
Renumber subsequent FAQ entries to maintain continuity.
2026-04-29 09:58:07 +08:00
liujinye 2df92aabf9 chore(ci): switch workflows to use dev branch
Switch all workflow references from @trunk to @dev branch
of public-actions for unified workflow management.
2026-03-20 15:28:19 +08:00
zhangxiaowei16 0bf088c117 docs: add repo mirror URL for GitHub download option 2026-03-02 19:41:23 +08:00
zhangxiaowei16 8d612d05c0 Hardware adaptation guide 2026-02-06 17:41:48 +08:00
zhangxiaowei16 2cef4a73a4 Hardware adaptation guide 2026-02-06 17:41:48 +08:00
zhangxiaowei16 d1144f0c7b Add openvela Highlights 2026-02-06 11:29:09 +08:00
zhangxiaowei16 a009c9037b Product documentation for version 5.4 2026-02-06 11:29:09 +08:00
v-tangmeng ac96045fd1 update release notes for trunk-5.4
Signed-off-by: v-tangmeng <v-tangmeng@xiaomi.com>
2026-02-05 10:58:24 +08:00
v-tangmeng af01300b82 Update release notes for trunk-5.4
Signed-off-by: v-tangmeng <v-tangmeng@xiaomi.com>
2026-02-04 17:26:32 +08:00
zhangxiaowei16 689ad95a62 Modify the openvela build script based on Ubuntu 2026-02-03 19:57:23 +08:00
zhangxiaowei16 ed114dbaf9 openvela VS Code Plugin User Guide 2026-02-02 15:08:34 +08:00
zhangxiaowei16 917bba073c Add the git lfs install command 2026-01-29 10:07:54 +08:00
zhangxiaowei16 c5bcb2932e Add the git lfs install command 2026-01-29 10:07:54 +08:00
zhangxiaowei16 4f8acc5e16 Add the git lfs install command 2026-01-29 10:07:54 +08:00
zhangxiaowei16 0649c6233b Add the git lfs install command 2026-01-28 14:12:56 +08:00
zhangxiaowei16 7ba6ed4d75 Add linkds to development boards and chips 2026-01-22 11:28:41 +08:00
zhangxiaowei16 952e91c630 update document development process 2026-01-15 10:09:04 +08:00
zhangxiaowei16 d292b2d0d6 add openvela-faq.md covering tech & community Q&A 2026-01-14 17:23:56 +08:00
zhangxiaowei16 0e6d4fbe2c Priority Inheritance Rules for Signaling Semaphores 2026-01-08 19:55:20 +08:00
zhangxiaowei16 12d45a294f Model Conversion and Code Integration 2026-01-08 14:15:23 +08:00
zhangxiaowei16 9407f8d73f Model Conversion and Code Integration 2026-01-08 09:12:18 +08:00
zhangxiaowei16 c1d0fa7530 Configure TFLite Micro Development Environment 2026-01-07 14:23:06 +08:00
zhangxiaowei16 7bbef47dae Configure TFLite Micro Development Environment 2026-01-07 14:23:06 +08:00
zhangxiaowei16 a04a168480 TLLite Micro Architecture Analysis and Integration 2026-01-07 09:11:03 +08:00
zhangxiaowei16 e80f1d2916 TLLite Micro Architecture Analysis and Integration 2026-01-06 10:07:02 +08:00
zhangxiaowei16 ba5ed2eacf TFLite Micro Overview 2026-01-05 10:42:07 +08:00
zhangxiaowei16 36232a9fd7 TFLite Micro Overview 2026-01-04 09:47:26 +08:00
zhangxiaowei16 f056adf2f2 TensorFlow Lite for Microcontrollers Technical Overview 2026-01-04 09:47:26 +08:00
zhangxiaowei16 a127d5dd91 TensorFlow Lite for Microcontrollers Technical Overview 2025-12-31 14:55:42 +08:00
zhangxiaowei16 1b369ff501 TensorFlow Lite for Microcontrollers Technical Overview 2025-12-31 14:55:42 +08:00
zhangxiaowei16 63dcddf2f0 TensorFlow Lite for Microcontrollers Technical Overview 2025-12-31 14:55:42 +08:00
zhangxiaowei16 d4536f1c43 openvela Sim Audio Development and Testing Guid 2025-12-30 16:08:13 +08:00
zhangxiaowei16 c7c540f472 openvela Sim Audio Development and Testing Guid 2025-12-30 16:08:13 +08:00
zhangxiaowei16 1870c8f2d5 Merge dev into trunk 2025-12-26 15:23:39 +08:00
zhangxiaowei16 8aab4f69b0 Update the English version of the Hello World document 2025-12-26 14:59:41 +08:00
zhangxiaowei16 70764b3a61 Add Gitee and GitCode download options 2025-12-26 08:51:57 +08:00
zhangxiaowei16 0e0c15c12b FC7300F8M-EVB Development Board openvela Operation Guide 2025-12-24 17:54:04 +08:00
zhangxiaowei16 202d8bfa52 SIL SocketCAN Functional Testing Guide 2025-12-24 09:43:16 +08:00
zhangxiaowei16 f05b040dfb Add Infineon TC4D9-EVB and Flagchip FC7300F8M-EVB 2025-12-23 15:37:26 +08:00
zhangxiaowei16 d5b124c1e3 Add Infineon TC4D9-EVB and Flagchip FC7300F8M-EVB 2025-12-23 15:37:26 +08:00
zhangxiaowei16 4f25280885 add openvela WeChat community QR codes to README 2025-12-23 14:44:24 +08:00
zhangxiaowei16 daed5ebf8e Remove unnecessary information that might confuse developers 2025-12-23 10:07:54 +08:00
zhangxiaowei16 cd6ed80a15 Add usage guides for SocketCAN and FC7300/TC4D9 boards 2025-12-18 08:48:18 +08:00
zhangxiaowei16 182fe127dd Update license statement for openvela 2025-12-15 22:20:26 +08:00
zhangxiaowei16 53b7c507f5 Hello World supports CMake-based building 2025-12-10 10:21:07 +08:00
zhangxiaowei16 531e9bcaae Hello World supports CMake-based building 2025-12-10 09:46:00 +08:00
zhangxiaowei16 26863182c3 Hello World supports CMake-based building 2025-12-09 17:08:35 +08:00
zhangxiaowei16 891dbcc0f1 Optimizing English Documentation Translation 2025-11-19 20:26:18 +08:00
zhangxiaowei16 53ccc1dd9b Add macOS quickstart 2025-10-11 10:54:42 +08:00
zhangxiaowei16 1bab4b4faa Add macOS quickstart 2025-10-11 10:54:42 +08:00
zhangxiaowei16 01149e37d1 Update openvela Versioning Strategy 2025-09-22 20:18:35 +08:00
zhangxiaowei16 cb8e826498 Update release notes for trunk-5.2 2025-09-22 14:46:56 +08:00
Your Name 58025ef7f7 update Whack-a-Mole REAMDE path 2025-09-20 12:31:43 +08:00
zhangxiaowei16 8ef2472d77 Optimize the demo name translation. 2025-09-19 17:53:55 +08:00
zhangxiaowei16 f03dd7d2cf Modify the code branch in the Release Notes to trunk-5.2 2025-09-19 16:54:10 +08:00
zhangxiaowei16 e8e90c3996 Replace trunk-5.2 with trunk in content 2025-09-18 17:16:18 +08:00
zhangxiaowei16 935d419691 Replace trunk-5.2 with trunk in content 2025-09-18 17:16:18 +08:00
zhangxiaowei16 dbc4cc3987 Modify openvela trunk 2025-09-18 17:16:18 +08:00
zhangxiaowei16 63d8ecade1 Modify openvela trunk 2025-09-18 17:16:18 +08:00
zhangxiaowei16 c5039eb7a0 Modify openvela trunk-5.2 2025-09-18 15:20:51 +08:00
zhangxiaowei16 afbe1041a1 Modify openvela trunk-5.2 2025-09-18 15:20:51 +08:00
Your Name f2048e0a90 Merge the dev branch into the trunk branch. 2025-09-17 18:09:56 +08:00
zhangxiaowei16 bef74a1640 Add openvela trunk-5.2 2025-09-17 15:35:41 +08:00
zhangxiaowei16 b038a81788 Add openvela trunk-5.2 2025-09-17 15:35:41 +08:00
zhangxiaowei16 59ec889b94 Add openvela trunk-5.2 2025-09-17 15:35:41 +08:00
zhangxiaowei16 8b215997c8 Add openvela trunk-5.2 2025-09-17 15:35:41 +08:00
zhangxiaowei16 affeced945 Optimize document content 2025-09-17 09:51:07 +08:00
zhangxiaowei16 ceb2f53ab1 Optimize document content 2025-09-16 19:52:55 +08:00
zhangxiaowei16 f234b27ff5 Optimize document content 2025-09-16 19:52:55 +08:00
zhangxiaowei16 0919d784cb Optimize document content 2025-09-16 19:52:55 +08:00
zhangxiaowei16 2d302e6ba7 Change the file paths due to the branch switch 2025-09-09 14:02:48 +08:00
openvela-robot 66483f41d2 update .github 2025-07-24 15:33:25 +08:00
229 changed files with 203 additions and 64912 deletions

2
.github/CODEOWNERS vendored
View File

@ -1 +1 @@
* @aiduxiaoxiong @smile0425 @tanghao-xiaomi @TangMeng12 @yanxingyu17
* @xiaoxiang781216 @aiduxiaoxiong @smile0425 @tanghao-xiaomi @TangMeng12 @yanxingyu17

View File

@ -1,4 +1,4 @@
*Note: Please adhere to [Contributing Guidelines](https://github.com/open-vela/docs/blob/dev/CONTRIBUTING.md).*
*Note: Please adhere to [Contributing Guidelines](https://github.com/open-vela/docs/blob/trunk/CONTRIBUTING.md).*
## Summary

View File

@ -6,8 +6,6 @@ name: docs
on:
pull_request_target:
types: [opened, reopened, synchronize]
issue_comment:
types: [created]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

View File

@ -2,7 +2,7 @@ name: 'Close stale issues and PR'
on:
schedule:
- cron: '30 1 * * *'
workflow_dispatch: # 允许手动触发
workflow_dispatch: # Manual triggering is allowed.
jobs:
stale:

15
.gitignore vendored
View File

@ -1,15 +0,0 @@
# Sphinx build artifacts (deprecated)
doxygen/_build/
doxygen/doxygen/
# Python
__pycache__/
*.pyc
*.pyo
# Editor
.vscode/
.idea/
*.swp
*.swo
.DS_Store

View File

@ -28,7 +28,7 @@ The name "Vela" is originated from the Latin term for "sail," which is also the
- **Maintenance and Testing Tools**
Maintenance and testing tools include common utilities and diagnostic frameworks. In addition to standard tools like Logger and Debugger, they feature the Emulator — a high-fidelity device simulator that supports full functional emulation, including CPU instruction-set simulation. The Emulator currently supports multiple product form factors, including smart panels, smartwatches, smart bands, and smart screen speakers. By leveraging the Emulator's PC-based debugging tools, developers can perform application development and testing without physical devices, significantly reducing both development and debugging efforts.
Maintenance and testing tools include common utilities and diagnostic frameworks. In addition to standard tools like Logger and Debugger, they feature the Emulator — a high-fidelity device simulator that supports full functional emulation, including CPU instruction-set simulation. The Emulator currently supports multiple product form factors, including smart panels, smartwatches, smart bands, and smart screen speakers. By leveraging the Emulators PC-based debugging tools, developers can perform application development and testing without physical devices, significantly reducing both development and debugging efforts.
## Technical Advantages
@ -46,7 +46,7 @@ The name "Vela" is originated from the Latin term for "sail," which is also the
- **Standard Compliant and High Portability**
openvela Kernel is built upon Apache NuttX, which is often referred to as "tiny Linux". With this foundation, openvela achieves a high degree of conformity with the POSIX standard. Our team has been continually enhancing its POSIX compatibility, which has now reached an impressive 89%. Because of this standards conformance, software developed under other standard OSs (such as Linux) can be easily ported to openvela with minimum effort.
openvela Kernel is built upon Apache NuttX, which is often referred to as "tiny Linux". With this foundation, openvela achieves a high degree of conformity with the POSIX standard. Our team has been continually enhancing its POSIX compatibility, which has now reached an impressive 88%. Because of this standards conformance, software developed under other standard OSs (such as Linux) can be easily ported to openvela with minimum effort.
- **Comprehensive Connectivity Suite**
@ -54,7 +54,7 @@ The name "Vela" is originated from the Latin term for "sail," which is also the
- **Rich Developer Tools**
openvela offers a comprehensive suite of developer tools, including system monitoring, performance analysis, debugger, trace, crash dump, and log analysis tools.
openvela offers a comprehensive suite of developer tools, including system monitoring, performance analysis, debugger, trace, crash dumb, and log analysis tools.
## Hardware Support
@ -64,10 +64,6 @@ The name "Vela" is originated from the Latin term for "sail," which is also the
## What's New
- **openvela Official Website Launched**: openvela now has its own official website, providing developers with a more convenient channel for accessing project information, documentation, community updates, and more. Visit the [openvela Official Website](https://openvela.com).
- **First openvela Officially Certified Development Board**: The **[Gemini-S1](https://rivotek.feishu.cn/wiki/Onndw4lmniFBnEk0Rb7cDbwOnTc)** development board, independently developed by Runxinwei Intelligent Technology Co., Ltd., has become the first development board to pass the openvela official compatibility certification, marking a significant milestone in the openvela ecosystem.
- **Significant Hardware Ecosystem Expansion**: Added support for **Infineon AURIX™ TC4**, **Flagchip MCU**, and the **QEMU-R52 SIL** platform. (View [TC4 Guide](./en/quickstart/development_board/tc4d9_evb_guide.md) / [Flagchip Guide](./en/quickstart/development_board/fc7300f8m_evb_guide.md))
- **Enhanced Ubuntu Development Experience**: The OpenVela VS Code plugin now **fully supports the Ubuntu environment**. Linux developers can enjoy a seamless, end-to-end workflow—from project creation and build to system debugging—significantly boosting development efficiency. Get started: [VS Code Plugin Guide](./en/quickstart/vscode_plugin_usage.md).
@ -134,8 +130,6 @@ If you want to experience openvela, we provide a fully functional emulator that
[Quick Start (Ubuntu)](./en/quickstart/openvela_ubuntu_quick_start.md)
> **AI-Assisted Setup**: If you use an AI coding assistant, simply run `git clone https://github.com/open-vela/.claude.git .claude`, then tell the AI "Help me set up the openvela development environment" to automate the entire setup process. See [openvela AI Skills](https://github.com/open-vela/.claude) for details.
### Quick App Development
[Quick App Quick Start](https://iot.mi.com/vela/quickapp/zh/guide/start/use-ide.html)
@ -155,7 +149,6 @@ If you want to experience openvela, we provide a fully functional emulator that
## Developer Documentation
- [Documentation Center](https://doc.openvela.com/document)
- [API Reference](./en/api/index.md) — Complete API specification for kernel, network, and application framework interfaces
## Application Example Center
@ -168,17 +161,17 @@ Here are some typical native application examples demonstrating the usage of dif
- [Music Player](./en/demo/Music_Player_Example.md): Demonstrates audio playback, playlist management, and background services.
- [Smart Band](./en/demo/Smart_Band_Example.md): Demonstrates sleep monitoring, heart rate monitoring, music playback, and a stopwatch.
- [Cycling Computer](./en/demo/X_Track.md): Demonstrates GPS positioning, real-time data display, and route tracking.
- [Calculator](../../../../open-vela/packages_demos/blob/dev/calculator/Readme.md): A basic example of UI and logic interaction.
- [Relation Calculator](../../../../open-vela/packages_demos/blob/dev/relation_calculator/Readme.md): Demonstrates complex conditional logic and algorithm implementation.
- [Whack-a-Mole](../../../../open-vela/packages_demos/blob/dev/Whackmole/README.md): Demonstrates a game loop, random number generation, and animation effects.
- [Calculator](../../../../open-vela/packages_demos/blob/trunk/calculator/Readme.md): A basic example of UI and logic interaction.
- [Relation Calculator](../../../../open-vela/packages_demos/blob/trunk/relation_calculator/Readme.md): Demonstrates complex conditional logic and algorithm implementation.
- [Whack-a-Mole](../../../../open-vela/packages_demos/blob/trunk/Whackmole/README.md): Demonstrates a game loop, random number generation, and animation effects.
To see the full list of native apps, please visit the [Native App Examples Repository](../../../packages_demos/blob/dev/README_zh-cn.md).
To see the full list of native apps, please visit the [Native App Examples Repository](../../../packages_demos/blob/trunk/README.md).
### Quick Apps
- [Mi Band Weather App](../../.././packages_fe_examples/blob/dev/weather/README.md): Presents a clean and intuitive seven-day weather forecast.
- [Music Player](../../.././packages_fe_examples/blob/dev/player/README.md): Demonstrates a basic music player, including playback, volume control, and playlist viewing.
- [Calendar](../../.././packages_fe_examples/blob/dev/calendar/README.md): Demonstrates a basic calendar.
- [Mi Band Weather App](../../.././packages_fe_examples/blob/trunk/weather/README.md): Presents a clean and intuitive seven-day weather forecast.
- [Music Player](../../.././packages_fe_examples/blob/trunk/player/README.md): Demonstrates a basic music player, including playback, volume control, and playlist viewing.
- [Calendar](../../.././packages_fe_examples/blob/trunk/calendar/README.md): Demonstrates a basic calendar.
More Quick App examples are continuously being added. To see all examples, please visit the [Quick App Examples Repository](../../../packages_fe_examples).
@ -207,7 +200,7 @@ The openvela project consists of multiple independent repositories. Its licensin
We welcome you to interact with and contribute to the openvela community through our various channels.
### Technical Discussions and Contributions
## Technical Discussions and Contributions
- **Issues**: If you have any questions, suggestions, or find any bugs, submit a new issue on the Issues page. Try to provide detailed information, so that we can understand and solve the problem faster.
- **Pull Requests**: If you find an issue and have fixed it, you are welcome to submit a Pull Request. Please make sure to follow our [Contribution Guide](./CONTRIBUTING.md).
@ -221,3 +214,4 @@ Welcome to the **OpenVela** community! Scan the QR codes below to follow our Off
| :---------------------------------------------------------------------: | :-------------------------------------------------: |
| <img src="./images/openvela_WeChat_Official_Account.png" width="200" /> | <img src="./images/assistant_qr.jpg" width="200" /> |
| **Follow Us**<br>Get the latest updates and technical articles | **Join the Group**<br>Scan to add assistant |

View File

@ -48,7 +48,7 @@ Vela 的命名源自拉丁语中船帆的含义,也是南方星空中船帆星
- **标准兼容和高可移植性**
openvela 内核基于 Apache NuttX ,这个被称为 "Tiny Linux" 的系统为 openvela 提供了高标准的 POSIX 兼容性。通过持续提升其 POSIX 兼容性openvela 当前已达到 89% 的兼容水平。这种高标准的兼容性意味着在其他标准操作系统(例如 Linux上开发的软件可以轻松迁移到 openvela几乎不需要额外的工作。
openvela 内核基于 Apache NuttX ,这个被称为 “Tiny Linux” 的系统为 openvela 提供了高标准的 POSIX 兼容性。通过持续提升其 POSIX 兼容性openvela 当前已达到 88% 的兼容水平。这种高标准的兼容性意味着在其他标准操作系统(例如 Linux上开发的软件可以轻松迁移到 openvela几乎不需要额外的工作。
- **全面的连接套件**
@ -65,10 +65,6 @@ Vela 的命名源自拉丁语中船帆的含义,也是南方星空中船帆星
## 最新动态
- openvela 官方网站正式上线openvela 现已拥有独立的官方网站,为开发者提供更加便捷的信息获取渠道,包括项目介绍、文档中心、社区动态等。欢迎访问 [openvela 官网](https://openvela.com)。
- openvela 生态迎来重要里程碑:润芯微智能科技股份有限公司自主研发的 **[Gemini-S1](https://rivotek.feishu.cn/wiki/Onndw4lmniFBnEk0Rb7cDbwOnTc)** 开发板成为首款通过 openvela 官方兼容性认证的开发板,标志着 openvela 生态建设迈出了坚实的一步。
- 硬件生态大幅扩展:新增对 **英飞凌 AURIX™ TC4**、**旗芯微 (Flagchip) MCU** 以及 **QEMU-R52 SIL** 平台的适配支持。(查看 [TC4 指南](./zh-cn/quickstart/development_board/tc4d9_evb_guide.md) / [旗芯微指南](./zh-cn/quickstart/development_board/fc7300f8m_evb_guide.md)
- Ubuntu 开发体验升级openvela VS Code 插件现已**完美支持 Ubuntu 环境**。Linux 开发者现在也可以享受从项目创建、编译构建到系统调试的一站式流畅体验,开发效率显著提升。即刻体验:[VS Code 插件使用指南](./zh-cn/quickstart/vscode_plugin_usage.md)。
@ -135,8 +131,6 @@ openvela 采用双分支模型来平衡系统的创新性与稳定性。请根
[快速入门Ubuntu](./zh-cn/quickstart/openvela_ubuntu_quick_start.md)
> **AI 辅助搭建**:如果您使用 AI 编程助手,只需 `git clone https://github.com/open-vela/.claude.git .claude`,然后告诉 AI "帮我搭建 openvela 开发环境",即可自动完成全部搭建流程。详见 [openvela AI Skills](https://github.com/open-vela/.claude)。
### 快应用开发
[快应用快速入门](https://iot.mi.com/vela/quickapp/zh/guide/start/use-ide.html)
@ -156,7 +150,6 @@ openvela 采用双分支模型来平衡系统的创新性与稳定性。请根
## 开发者文档
- [文档中心](https://doc.openvela.com/document)
- [API 参考文档](./zh-cn/api/index.md) — 内核接口、网络接口、应用框架 API 完整说明
## 应用示例中心
@ -169,17 +162,17 @@ openvela 采用双分支模型来平衡系统的创新性与稳定性。请根
- [音乐播放器](./zh-cn/demo/Music_Player_Example_zh-cn.md):演示音频播放、列表管理和后台服务。
- [智能手环](./zh-cn/demo/Smart_Band_Example_zh-cn.md):演示睡眠监测、心率监测、音乐播放、秒表计时。
- [自行车码表](./zh-cn/demo/X_Track_zh-cn.md):演示 GPS 定位、实时数据显示和运动轨迹记录。
- [计算器](../../../../open-vela/packages_demos/blob/dev/calculator/Readme.md):一个基础的 UI 与逻辑交互示例。
- [亲戚计算器](../../../../open-vela/packages_demos/blob/dev/relation_calculator/Readme_zh-cn.md):演示复杂的条件逻辑与算法实现。
- [打地鼠](../../../../open-vela/packages_demos/blob/dev/Whackmole/README_zh-cn.md):演示游戏循环、随机数生成和动画效果。
- [计算器](../../../../open-vela/packages_demos/blob/trunk/calculator/Readme.md):一个基础的 UI 与逻辑交互示例。
- [亲戚计算器](../../../../open-vela/packages_demos/blob/trunk/relation_calculator/Readme_zh-cn.md):演示复杂的条件逻辑与算法实现。
- [打地鼠](../../../../open-vela/packages_demos/blob/trunk/Whackmole/README_zh-cn.md):演示游戏循环、随机数生成和动画效果。
查看完整的原生应用列表,请访问[原生应用示例仓库](../../../packages_demos/blob/dev/README_zh-cn.md)。
查看完整的原生应用列表,请访问[原生应用示例仓库](../../../packages_demos/blob/trunk/README_zh-cn.md)。
### 快应用Quick Apps
- [小米手环天气预报应用](../../.././packages_fe_examples/blob/dev/weather/README.md):提供简洁直观的未来七日天气信息展示。
- [音乐播放器](../../.././packages_fe_examples/blob/dev/player/README.md):演示一个基础的音乐播放器,包含音乐的播放,音量调节,歌单查看。
- [日历](../../.././packages_fe_examples/blob/dev/calendar/README.md):演示一个基础的日历。
- [小米手环天气预报应用](../../.././packages_fe_examples/blob/trunk/weather/README.md):提供简洁直观的未来七日天气信息展示。
- [音乐播放器](../../.././packages_fe_examples/blob/trunk/player/README.md):演示一个基础的音乐播放器,包含音乐的播放,音量调节,歌单查看。
- [日历](../../.././packages_fe_examples/blob/trunk/calendar/README.md):演示一个基础的日历。
快应用相关示例正在持续丰富中。查看所有示例,请访问[快应用示例仓库](../../../packages_fe_examples)。

5
en/api/README.md Normal file
View File

@ -0,0 +1,5 @@
# API Reference
\[ English | [简体中文](../../zh-cn/api/README.md) \]
- [Bluetooth](bluetooth/README.md)

View File

@ -0,0 +1,5 @@
# Bluetooth API Reference
\[ English | [简体中文](../../../zh-cn/api/bluetooth/README.md) \]
Table of Contents:

View File

@ -1,247 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/binder/binder.md) \]
# Binder Inter-Process Communication (IPC) Development Guide
Binder is an efficient inter-process communication (IPC) transport mechanism that enables data exchange and remote method invocation between different processes.
## 1. Core Architecture
The Binder mechanism consists of the following four core components:
- **Binder Driver**: Resides in kernel space and handles the low-level details of inter-process communication, including packet transmission and thread management.
- **ServiceManager**: A special daemon process that acts as a context manager, responsible for registering and looking up Binder services.
- **Binder Server**: Implements specific service functionality and responds to requests from other processes via the Binder mechanism.
- **Binder Client**: The process that uses services, sending requests to the server and receiving responses via the Binder mechanism.
## 2. System Configuration and Startup
### 2.1 Kconfig Configuration
Before using Binder, ensure the following basic configurations are enabled:
```kconfig
CONFIG_DRIVERS_BINDER # Kernel driver switch
CONFIG_ANDROID_BINDER # Binder library switch
CONFIG_ANDROID_SERVICEMANAGER # Binder daemon
CONFIG_BINDER_EXAMPLES # Binder examples switch
```
If using libuv for event loop polling, enable the following after enabling `CONFIG_BINDER_EXAMPLES`:
```kconfig
CONFIG_LIBUV # Enable libuv support
```
### 2.2 Runtime Startup
Before performing Binder communication, the ServiceManager daemon must be started first:
```bash
nsh> servicemanager &
```
## 3. How It Works
The Binder communication flow is as follows:
1. Developers define communication interfaces through **AIDL** files.
2. The **server** implements the interface and registers the service with ServiceManager.
3. The **client** queries ServiceManager for a specific service name and obtains a reference to the server's Binder object.
4. The **client** calls predefined interface methods. The proxy code generated by AIDL and the Binder library serialize the parameters and write the request to the kernel driver.
5. The **Binder driver** forwards the client request to the server.
6. The **server** receives the request, performs the specific operation, and returns the result back to the client via the same path.
## 4. Interface Definition (AIDL)
AIDL (Android Interface Definition Language) is used to define inter-process communication interfaces, simplifying cross-process method invocation.
### 4.1 Interface Definition Example
Create a simple AIDL interface file:
```java
interface ITestStuff {
void write(int sample);
void read(int idx);
}
```
### 4.2 Code Generation
The AIDL tool generates the following C++ files based on the above definition, containing the client proxy class (Bp) and server stub class (Bn):
- `BnTestStuff.h`
- `BpTestStuff.h`
- `ITestStuff.h`
- `ITestStuff.cpp`
## 5. Implementation Patterns
Depending on the application scenario, there are three main implementation patterns for Binder servers.
### Pattern 1: Binder Thread Pool (Standard Pattern)
This pattern is suitable for standard blocking service calls.
#### 1. Server Implementation
- **Create service instance**: Inherit from the AIDL-generated `Bn` class and implement the interface.
```cpp
sp<ITestServer> testServer = new ITestServer;
```
- **Define interface methods**:
```cpp
Status read(int32_t sample) { /* implementation logic */ }
Status write(int32_t index) { /* implementation logic */ }
```
- **Register service**:
```cpp
sp<IServiceManager> sm(defaultServiceManager());
sm->addService(String16("aidldemo.service"), testServer);
```
- **Start thread pool**: Add the current thread to the Binder thread pool to process requests.
```cpp
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
```
#### 2. Client Implementation
- **Get service**:
```cpp
sp<IServiceManager> sm(defaultServiceManager());
sp<IBinder> binder = sm->getService(String16("aidldemo.service"));
```
- **Cast to proxy interface**:
```cpp
sp<ITestStuff> service = interface_cast<ITestStuff>(binder);
```
- **Call interface**:
```cpp
service->write(123);
service->read(456);
```
---
### Pattern 2: Libuv Main Loop (Asynchronous Event-Driven)
This pattern is suitable for applications that need to integrate with the libuv event loop.
#### 1. Server Implementation
- **Create and register service**:
```cpp
sp<ILibuvServer> testServer = new ILibuvServer;
// ... implement interface and register with ServiceManager (same as Pattern 1) ...
```
- **Configure Binder polling**: Obtain the file descriptor (FD) of the Binder driver.
```cpp
IPCThreadState::self()->setupPolling(&fd);
```
- **Initialize libuv handle**:
```cpp
uv_poll_init(uv_default_loop(), &binder_handle, fd);
```
- **Start listening**: Trigger the callback `uv_binder_cb` when the FD is readable to process the message queue.
```cpp
uv_poll_start(&binder_handle, UV_READABLE, uv_binder_cb);
```
- **Run event loop**:
```cpp
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
```
- **Release resources**:
```cpp
uv_close((uv_handle_t*)&binder_handle, NULL);
IPCThreadState::self()->stopProcess();
```
#### 2. Client Implementation
Refer to Pattern 1.
---
### Pattern 3: Epoll Main Loop (Native Linux Event-Driven)
This pattern is suitable for applications that use the native epoll mechanism for event management.
#### 1. Server Implementation
- **Create and register service**:
```cpp
// Refer to Pattern 1 to create Bn class instance and register
```
- **Create epoll instance**:
```cpp
int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
```
- **Configure Binder polling**:
```cpp
int fd;
IPCThreadState::self()->setupPolling(&fd);
```
- **Register epoll event**:
```cpp
struct epoll_event ev;
ev.events = EPOLLIN;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
```
- **Event loop processing**:
```cpp
while (1) {
struct epoll_event events[1];
int numEvents = epoll_wait(epoll_fd, events, 1, -1);
if (numEvents < 0) {
if (errno == EINTR) {
continue;
}
break;
}
if (numEvents > 0 && (events[0].events & EPOLLIN)) {
ALOGI("process binder transaction");
// Process commands and flush buffer
IPCThreadState::self()->handlePolledCommands();
IPCThreadState::self()->flushCommands(); // flush BC_FREE_BUFFER
}
}
```
#### 2. Client Implementation
Refer to Pattern 1.

View File

@ -1,292 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_a2dp.md) \]
# Bluetooth A2DP API
The openvela Bluetooth A2DP (Advanced Audio Distribution Profile) interface supports audio stream sending (Source) and receiving (Sink).
Header files: #include "bt_a2dp.h", #include "bt_a2dp_sink.h", #include "bt_a2dp_source.h"
## openvela Implementation Notes
- **Dual-role support**: Source (audio sender) and Sink (audio receiver)
- **Codecs**: Supports SBC and AAC
- **Transport modes**: Supports hardware offloading and non-offloading modes
## Connection State Machine
The state transitions during A2DP connection establishment, audio streaming, and disconnection are shown below:
![A2DP State Machine](figures/a2dp.png)
State definitions:
- **Idle**: No A2DP connection is established.
- **Opening**: An A2DP connection is being established (after the local side initiates `A2DP connect`).
- **Opened**: The A2DP signaling connection has been established and the audio stream is ready.
- **Started**: The audio stream has started and audio data is being transmitted.
- **Closing**: The A2DP connection is being torn down until the peer confirms `A2DP disconnected`.
## Synchronous Interfaces
### bt_a2dp_sink_unregister_callbacks
```c
bool bt_a2dp_sink_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister callback functions and stop receiving state change notifications.
**Parameters**:
- `ins` Bluetooth client instance.
- `cookie` User context.
**Returns**:
Returns the callback cookie on success, or NULL on failure or if already registered.
### bt_a2dp_sink_is_connected
```c
bool bt_a2dp_sink_is_connected(bt_instance_t* ins, bt_address_t* addr);
```
Check whether the A2DP Sink is connected to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns true if connected, false otherwise.
### bt_a2dp_sink_is_playing
```c
bool bt_a2dp_sink_is_playing(bt_instance_t* ins, bt_address_t* addr);
```
Check whether audio is currently playing.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns true if playing, false otherwise.
### bt_a2dp_sink_get_connection_state
```c
profile_connection_state_t bt_a2dp_sink_get_connection_state(bt_instance_t* ins, bt_address_t* addr);
```
Get the A2DP Sink connection state with the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns the current connection state.
### bt_a2dp_sink_connect
```c
bt_status_t bt_a2dp_sink_connect(bt_instance_t* ins, bt_address_t* addr);
```
Initiate an A2DP Sink connection to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_a2dp_sink_disconnect
```c
bt_status_t bt_a2dp_sink_disconnect(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the A2DP Sink connection from the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_a2dp_source_unregister_callbacks
```c
bool bt_a2dp_source_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister callback functions and stop receiving state change notifications.
**Parameters**:
- `ins` Bluetooth client instance.
- `cookie` User context.
**Returns**:
Returns the callback cookie on success, or NULL on failure or if already registered.
### bt_a2dp_source_is_connected
```c
bool bt_a2dp_source_is_connected(bt_instance_t* ins, bt_address_t* addr);
```
Check whether the A2DP Source is connected to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns true if connected, false otherwise.
### bt_a2dp_source_is_playing
```c
bool bt_a2dp_source_is_playing(bt_instance_t* ins, bt_address_t* addr);
```
Check whether audio is currently playing.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns true if playing, false otherwise.
### bt_a2dp_source_get_connection_state
```c
profile_connection_state_t bt_a2dp_source_get_connection_state(bt_instance_t* ins, bt_address_t* addr);
```
Get the A2DP Source connection state with the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns the current connection state.
### bt_a2dp_source_connect
```c
bt_status_t bt_a2dp_source_connect(bt_instance_t* ins, bt_address_t* addr);
```
Initiate an A2DP Source connection to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the peer device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_a2dp_source_disconnect
```c
bt_status_t bt_a2dp_source_disconnect(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the A2DP Source connection from the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_a2dp_source_set_silence_device
```c
bt_status_t bt_a2dp_source_set_silence_device(bt_instance_t* ins, bt_address_t* addr, bool silence);
```
Set the device to silence mode.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `silence` Whether to enable silence mode (true for silent).
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_a2dp_source_set_active_device
```c
bt_status_t bt_a2dp_source_set_active_device(bt_instance_t* ins, bt_address_t* addr);
```
Set the active device for A2DP Source.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.

View File

@ -1,217 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_cs.md) \]
# Bluetooth Channel Sounding API
The openvela Bluetooth Channel Sounding (CS) interface provides distance measurement and positioning capabilities between Bluetooth devices. Based on the channel sounding technology introduced in the Bluetooth 5.4 specification, it supports centimeter-level ranging accuracy.
Header file: `#include <bt_cs.h>`
## openvela Implementation Notes
- **Ranging methods**: Supports automatic selection (AUTO), RSSI, and CS ranging methods
- **Role model**: Supports Initiator and Reflector roles
- **RAS features**: Supports real-time ranging data, lost data segment retrieval, abort operation, and data filtering
- **Callback notifications**: Ranging start, stop, and result events are delivered asynchronously via callbacks
- **Configuration dependency**: Test interface requires `CONFIG_BT_CS_RAS_TEST`
## Callback Management
### bt_cs_register_callbacks
```c
void* bt_cs_register_callbacks(bt_instance_t* ins, const cs_callbacks_t* callbacks);
```
Register CS event callback functions. After successful registration, the system notifies the application via callbacks when distance measurement starts, stops, or produces results.
**Parameters**:
- `ins` Bluetooth client instance.
- `callbacks` CS event callback function set, see `cs_callbacks_t`.
**Returns**:
On success, returns a callback cookie (non-NULL) for later unregistration; on failure, returns NULL.
### bt_cs_unregister_callbacks
```c
bool bt_cs_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister previously registered CS event callback functions.
**Parameters**:
- `ins` Bluetooth client instance.
- `cookie` Cookie returned during callback registration.
**Returns**:
Returns `true` on success, `false` on failure.
## Distance Measurement
### bt_cs_start_distance_measurement
```c
bt_status_t bt_cs_start_distance_measurement(bt_instance_t* ins, const bt_distance_measurement_params_t* params);
```
Start distance measurement. Callbacks must be registered via `bt_cs_register_callbacks` before calling this function. Measurement results are delivered through the `cs_distance_measure_result_cb` callback.
**Parameters**:
- `ins` Bluetooth client instance.
- `params` Distance measurement parameters, see `bt_distance_measurement_params_t`.
**Returns**:
Returns `BT_STATUS_SUCCESS` on success, or an error code on failure.
### bt_cs_stop_distance_measurement
```c
bt_status_t bt_cs_stop_distance_measurement(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout);
```
Stop distance measurement.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Remote device address.
- `method` Ranging method (AUTO/RSSI/CS).
- `timeout` Whether stopping due to timeout.
**Returns**:
Returns `BT_STATUS_SUCCESS` on success, or an error code on failure.
## Capability Query
### bt_get_cs_max_supported_security_level
```c
bt_status_t bt_get_cs_max_supported_security_level(bt_instance_t* ins, bt_address_t* addr);
```
Get the maximum CS security level supported by the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Remote device address.
**Returns**:
Returns `BT_STATUS_SUCCESS` on success, or an error code on failure.
## Configuration Management
### bt_cs_set_config
```c
bt_status_t bt_cs_set_config(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params);
```
Set CS configuration parameters, including RAS features, role, antenna selection, and maximum transmit power.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Remote device address.
- `params` CS configuration parameters, see `bt_cs_set_params_t`.
**Returns**:
Returns `BT_STATUS_SUCCESS` on success, or an error code on failure.
## Data Structures
### bt_distance_measurement_params_t
Distance measurement parameters structure.
| Field | Type | Description |
| -------------------- | -------------- | ------------------------------------- |
| `addr` | `bt_address_t` | Remote device address |
| `method` | `uint8_t` | Ranging method (0=AUTO, 1=RSSI, 2=CS) |
| `role` | `uint8_t` | Role (initiator/reflector) |
| `interval_ms` | `uint16_t` | Measurement interval (milliseconds) |
| `duration_ms` | `uint16_t` | Measurement duration (milliseconds) |
| `submode` | `uint8_t` | CS submode |
| `max_steps` | `uint8_t` | Maximum steps |
| `mode0_steps` | `uint8_t` | Mode 0 steps |
| `rtt_type` | `uint8_t` | RTT type |
| `sync_phy` | `uint8_t` | Sync PHY |
| `channel_map` | `uint8_t` | Channel map |
| `antenna_paths_mask` | `uint8_t` | Antenna paths mask |
| `vendor_specific` | `uint8_t` | Vendor-specific parameter |
| `debug_flags` | `uint8_t` | Debug flags |
### bt_distance_measurement_result_t
Distance measurement result structure.
| Field | Type | Description |
| --------------------------- | --------- | ------------------------------ |
| `centimeter` | `uint8_t` | Distance (centimeters) |
| `error_centimeter` | `uint8_t` | Distance error (centimeters) |
| `azimuth_angle` | `uint8_t` | Azimuth angle |
| `error_azimuthAngle` | `uint8_t` | Azimuth angle error |
| `altitude_angle` | `uint8_t` | Altitude angle |
| `error_altitudeAngle` | `uint8_t` | Altitude angle error |
| `elapsed_realtime_nanos` | `long` | Elapsed realtime (nanoseconds) |
| `confidence_level` | `uint8_t` | Confidence level |
| `delay_spread_meters` | `double` | Delay spread (meters) |
| `detected_attack_level` | `uint8_t` | Detected attack level |
| `velocity_meters_persecond` | `double` | Velocity (meters/second) |
| `method` | `uint8_t` | Ranging method used |
### bt_cs_set_params_t
CS configuration parameters structure.
| Field | Type | Description |
| --------------------------- | ---------- | ------------------------------------------------- |
| `ras_feature` | `uint32_t` | RAS feature bits (see macro definitions below) |
| `role` | `uint8_t` | CS role bits (Bit 0: initiator, Bit 1: reflector) |
| `cs_sync_antenna_selection` | `uint8_t` | CS_SYNC antenna selection |
| `max_tx_power` | `int8_t` | Maximum TX power (dBm, range -127 to 20) |
### cs_callbacks_t
CS event callback function set.
| Field | Type | Description |
| -------------------------------- | ---------------- | ------------------------------------- |
| `size` | `size_t` | Structure size |
| `cs_distance_measure_started_cb` | Function pointer | Distance measurement started callback |
| `cs_distance_measure_stopped_cb` | Function pointer | Distance measurement stopped callback |
| `cs_distance_measure_result_cb` | Function pointer | Distance measurement result callback |
## Macro Definitions
### RAS Feature Bits
| Macro | Value | Description |
| --------------------------------------- | ----- | ----------------------------------- |
| `BT_CS_RAS_REAL_TIME_RANGING_DATA` | 0x01 | Real-time ranging data |
| `BT_CS_RAS_RETRIEVE_LOST_DATA_SEGMENTS` | 0x02 | Retrieve lost ranging data segments |
| `BT_CS_RAS_ABORT_OPERATION` | 0x04 | Abort operation |
| `BT_CS_RAS_FILTER_RANGING_DATA` | 0x08 | Filter ranging data |
### Antenna Selection
| Macro | Value | Description |
| ---------------------------------- | ----- | ---------------------------------------------- |
| `BT_CS_ANTENNA_SEL_1` | 0x01 | Use antenna identifier 1 |
| `BT_CS_ANTENNA_SEL_2` | 0x02 | Use antenna identifier 2 |
| `BT_CS_ANTENNA_SEL_3` | 0x03 | Use antenna identifier 3 |
| `BT_CS_ANTENNA_SEL_4` | 0x04 | Use antenna identifier 4 |
| `BT_CS_ANTENNA_SEL_SINGLE_REPEATE` | 0xFD | Antenna identifiers in single repetitive order |
| `BT_CS_ANTENNA_SEL_DOUBLE_REPEATE` | 0xFE | Antenna identifiers in double repetitive order |
| `BT_CS_ANTENNA_SEL_NO_RECOMMEND` | 0xFF | Host has no recommendation |
**openvela extension interface.**

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,948 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_gatt.md) \]
# Bluetooth GATT API
openvela Bluetooth GATT (Generic Attribute Profile) interface, supporting BLE data attribute read/write and notifications.
Header files: #include "bt_gattc.h", #include "bt_gatts.h"
## openvela Implementation Notes
- **Dual-role support**: Client (GATTC, initiates read/write requests) and Server (GATTS, provides services and characteristic values)
- **BLE core**: GATT is the fundamental protocol for BLE data exchange
## Synchronous Interfaces
### bt_gattc_create_connect
```c
bt_status_t bt_gattc_create_connect(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks);
```
Create a GATT client connection instance.
**Parameters**:
- `ins` Bluetooth client instance.
- `phandle` Output parameter, stores the GATT client handle.
- `callbacks` Callback function set.
**Returns**:
No return value.
### bt_gattc_delete_connect
```c
bt_status_t bt_gattc_delete_connect(gattc_handle_t conn_handle);
```
Delete a GATT client connection instance.
**Parameters**:
- `conn_handle` Connection handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_connect
```c
bt_status_t bt_gattc_connect(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type);
```
Initiate a connection to a remote device.
**Parameters**:
- `conn_handle` Connection handle.
- `addr` Bluetooth address of the remote device.
- `addr_type` BLE address type.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_disconnect
```c
bt_status_t bt_gattc_disconnect(gattc_handle_t conn_handle);
```
Disconnect from a remote device.
**Parameters**:
- `conn_handle` Connection handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_discover_service
```c
bt_status_t bt_gattc_discover_service(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid);
```
Discover GATT services on a remote device. Results are returned asynchronously via callback.
**Parameters**:
- `conn_handle` Connection handle.
- `filter_uuid` Service UUID filter (NULL means no filter).
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_get_attribute_by_handle
```c
bt_status_t bt_gattc_get_attribute_by_handle(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc);
```
Get GATT attribute information by attribute handle.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `attr_desc` Output parameter, stores the attribute description.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_get_attribute_by_uuid
```c
bt_status_t bt_gattc_get_attribute_by_uuid(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc);
```
Get GATT attribute information by UUID.
**Parameters**:
- `conn_handle` Connection handle.
- `start_handle` Start handle.
- `end_handle` End handle.
- `attr_uuid` Attribute UUID.
- `attr_desc` Output parameter, stores the attribute description.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_read
```c
bt_status_t bt_gattc_read(gattc_handle_t conn_handle, uint16_t attr_handle);
```
Read a GATT characteristic value or descriptor from a remote device. Results are returned asynchronously via callback.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_write
```c
bt_status_t bt_gattc_write(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
```
Write a GATT characteristic value or descriptor to a remote device, waiting for confirmation before returning the result via callback.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `value` Data to write.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_write_without_response
```c
bt_status_t bt_gattc_write_without_response(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
```
Write a GATT characteristic value to a remote device (Write Without Response), without waiting for confirmation.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `value` Data to write.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_write_with_signed
```c
bt_status_t bt_gattc_write_with_signed(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
```
Write a GATT characteristic value to a remote device (Signed Write), using signed authentication.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `value` Data to write.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_subscribe
```c
bt_status_t bt_gattc_subscribe(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value);
```
Subscribe to GATT characteristic value notifications or indications from a remote device.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `ccc_value` CCCD value (0 disable, 1 notification, 2 indication).
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_unsubscribe
```c
bt_status_t bt_gattc_unsubscribe(gattc_handle_t conn_handle, uint16_t attr_handle);
```
Unsubscribe from GATT characteristic value notifications or indications from a remote device.
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_exchange_mtu
```c
bt_status_t bt_gattc_exchange_mtu(gattc_handle_t conn_handle, uint32_t mtu);
```
Negotiate the ATT MTU size with a remote device, affecting the maximum data length per transfer.
**Parameters**:
- `conn_handle` Connection handle.
- `mtu` MTU value.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_update_connection_parameter
```c
bt_status_t bt_gattc_update_connection_parameter(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency, uint32_t timeout, uint32_t min_connection_event_length, uint32_t max_connection_event_length);
```
Update BLE connection parameters.
**Parameters**:
- `conn_handle` Connection handle.
- `min_interval` Minimum connection interval.
- `max_interval` Maximum connection interval.
- `latency` Peripheral latency.
- `timeout` Supervision timeout.
- `min_connection_event_length` Minimum connection event length.
- `max_connection_event_length` Maximum connection event length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_read_phy
```c
bt_status_t bt_gattc_read_phy(gattc_handle_t conn_handle);
```
Read the current PHY configuration. Results are returned asynchronously via callback.
**Parameters**:
- `conn_handle` Connection handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_update_phy
```c
bt_status_t bt_gattc_update_phy(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
```
Update the PHY configuration.
**Parameters**:
- `conn_handle` Connection handle.
- `tx_phy` Transmit PHY.
- `rx_phy` Receive PHY.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gattc_read_rssi
```c
bt_status_t bt_gattc_read_rssi(gattc_handle_t conn_handle);
```
Read the RSSI value of the connection. Results are returned asynchronously via callback.
**Parameters**:
- `conn_handle` Connection handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_register_service
```c
bt_status_t bt_gatts_register_service(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks);
```
Register a GATT service.
**Parameters**:
- `ins` Bluetooth client instance.
- `phandle` Output parameter, stores the GATT server handle.
- `callbacks` Callback function set.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_unregister_service
```c
bt_status_t bt_gatts_unregister_service(gatts_handle_t srv_handle);
```
Unregister a GATT service.
**Parameters**:
- `srv_handle` GATT service handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_connect
```c
bt_status_t bt_gatts_connect(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type);
```
Initiate a connection to a remote device.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
- `addr_type` BLE address type.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_connect_bear
```c
bt_status_t bt_gatts_connect_bear(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type, uint8_t bear_type);
```
Initiate a connection to a remote device with a specified bearer type.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
- `addr_type` BLE address type.
- `bear_type` Bearer type.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_disconnect
```c
bt_status_t bt_gatts_disconnect(gatts_handle_t srv_handle, bt_address_t* addr);
```
Disconnect from a remote device.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_add_attr_table
```c
bt_status_t bt_gatts_add_attr_table(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db);
```
Add an attribute table (services, characteristics, descriptors) to the local GATT server.
**Parameters**:
- `srv_handle` GATT service handle.
- `srv_db` GATT service attribute table.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_remove_attr_table
```c
bt_status_t bt_gatts_remove_attr_table(gatts_handle_t srv_handle, uint16_t attr_handle);
```
Remove an attribute table from the local GATT server.
**Parameters**:
- `srv_handle` GATT service handle.
- `attr_handle` Attribute handle.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_set_attr_value
```c
bt_status_t bt_gatts_set_attr_value(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
```
Set the value of a local GATT attribute.
**Parameters**:
- `srv_handle` GATT service handle.
- `attr_handle` Attribute handle.
- `value` Data to set.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_get_attr_value
```c
bt_status_t bt_gatts_get_attr_value(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t* length);
```
Get the value of a local GATT attribute.
**Parameters**:
- `srv_handle` GATT service handle.
- `attr_handle` Attribute handle.
- `value` Output buffer for the attribute value.
- `length` Output parameter, stores the data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_response
```c
bt_status_t bt_gatts_response(gatts_handle_t srv_handle, bt_address_t* addr, uint32_t req_handle, uint8_t* value, uint16_t length);
```
Respond to a GATT read/write request from a remote device.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
- `req_handle` Request handle.
- `value` Response data.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_notify
```c
bt_status_t bt_gatts_notify(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length);
```
Send a GATT notification to a subscribed remote device, without requiring confirmation.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
- `attr_handle` Attribute handle.
- `value` Notification data.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_indicate
```c
bt_status_t bt_gatts_indicate(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length);
```
Send a GATT indication to a subscribed remote device, requiring confirmation.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
- `attr_handle` Attribute handle.
- `value` Indication data.
- `length` Data length.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_read_phy
```c
bt_status_t bt_gatts_read_phy(gatts_handle_t srv_handle, bt_address_t* addr);
```
Read the current PHY configuration.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_gatts_update_phy
```c
bt_status_t bt_gatts_update_phy(gatts_handle_t srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
```
Update the PHY configuration.
**Parameters**:
- `srv_handle` GATT service handle.
- `addr` Bluetooth address of the remote device.
- `tx_phy` Transmit PHY.
- `rx_phy` Receive PHY.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
## Asynchronous Interfaces
### bt_gattc_create_connect_async
```c
bt_status_t bt_gattc_create_connect_async(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks, bt_gattc_create_connect_cb_t cb, void* userdata);
```
Create a GATT client connection instance (asynchronous version).
**Parameters**:
- `ins` Bluetooth client instance.
- `phandle` Output parameter, stores the GATT client handle.
- `callbacks` Callback function set.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_delete_connect_async
```c
bt_status_t bt_gattc_delete_connect_async(gattc_handle_t conn_handle, bt_status_cb_t bt_gattc_delete_connect_cb_t, void* userdata);
```
Delete a GATT client connection instance (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `bt_gattc_delete_connect_cb_t` Completion callback for connection deletion.
- `userdata` User data.
### bt_gattc_connect_async
```c
bt_status_t bt_gattc_connect_async(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type, bt_status_cb_t cb, void* userdata);
```
Initiate a connection to a remote device (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `addr` Bluetooth address of the remote device.
- `addr_type` BLE address type.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_disconnect_async
```c
bt_status_t bt_gattc_disconnect_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
```
Disconnect the ATT bearer connection (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_discover_service_async
```c
bt_status_t bt_gattc_discover_service_async(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid, bt_status_cb_t cb, void* userdata);
```
Discover GATT services (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `filter_uuid` Service UUID filter (NULL means no filter).
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_get_attribute_by_handle_async
```c
bt_status_t bt_gattc_get_attribute_by_handle_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_gattc_get_attribute_cb_t cb, void* userdata);
```
Get attribute by handle (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_get_attribute_by_uuid_async
```c
bt_status_t bt_gattc_get_attribute_by_uuid_async(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid, bt_gattc_get_attribute_cb_t cb, void* userdata);
```
Get attribute by UUID (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `start_handle` Start handle.
- `end_handle` End handle.
- `attr_uuid` Attribute UUID.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_read_async
```c
bt_status_t bt_gattc_read_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_status_cb_t cb, void* userdata);
```
Read attribute value by handle (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_write_async
```c
bt_status_t bt_gattc_write_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length, bt_status_cb_t cb, void* userdata);
```
Write attribute value (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `value` Data to write.
- `length` Data length.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_write_without_response_async
```c
bt_status_t bt_gattc_write_without_response_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length, bt_gattc_write_cb_t cb, void* userdata);
```
Write data to a specified attribute without response (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `value` Data to write.
- `length` Data length.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_subscribe_async
```c
bt_status_t bt_gattc_subscribe_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value, bt_status_cb_t cb, void* userdata);
```
Subscribe to notifications or indications (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `ccc_value` CCCD value (0 disable, 1 notification, 2 indication).
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_unsubscribe_async
```c
bt_status_t bt_gattc_unsubscribe_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_status_cb_t cb, void* userdata);
```
Disable the specified CCCD (Client Characteristic Configuration Descriptor) (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `attr_handle` Attribute handle.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_exchange_mtu_async
```c
bt_status_t bt_gattc_exchange_mtu_async(gattc_handle_t conn_handle, uint32_t mtu, bt_status_cb_t cb, void* userdata);
```
Exchange MTU size (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `mtu` MTU value.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_update_connection_parameter_async
```c
bt_status_t bt_gattc_update_connection_parameter_async(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency, uint32_t timeout, uint32_t min_connection_event_length, uint32_t max_connection_event_length, bt_status_cb_t cb, void* userdata);
```
Update BLE connection parameters (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `min_interval` Minimum connection interval.
- `max_interval` Maximum connection interval.
- `latency` Peripheral latency.
- `timeout` Supervision timeout.
- `min_connection_event_length` Minimum connection event length.
- `max_connection_event_length` Maximum connection event length.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_read_phy_async
```c
bt_status_t bt_gattc_read_phy_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
```
Read PHY configuration (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_update_phy_async
```c
bt_status_t bt_gattc_update_phy_async(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy, bt_status_cb_t cb, void* userdata);
```
Update PHY configuration (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `tx_phy` Transmit PHY.
- `rx_phy` Receive PHY.
- `cb` Completion callback function.
- `userdata` User data.
### bt_gattc_read_rssi_async
```c
bt_status_t bt_gattc_read_rssi_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
```
Read RSSI value (asynchronous version).
**Parameters**:
- `conn_handle` Connection handle.
- `cb` Completion callback function.
- `userdata` User data.

View File

@ -1,899 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_hfp.md) \]
# Bluetooth HFP API
openvela Bluetooth HFP (Hands-Free Profile) interface, supporting Bluetooth telephony functionality.
Header files: #include "bt_hfp.h", #include "bt_hfp_hf.h", #include "bt_hfp_ag.h"
## openvela Implementation Notes
- **Dual-role support**: HF (Hands-Free unit) and AG (Audio Gateway)
- **Features**: Answer/hang up calls, volume control, voice recognition, phonebook access
## Synchronous Interfaces
### bt_hfp_hf_unregister_callbacks
```c
bool bt_hfp_hf_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister callback functions and stop receiving state change notifications.
**Parameters**:
- `cookie` User context.
- `ins` Bluetooth client instance.
**Returns**:
Returns true on success, or false on failure.
### bt_hfp_hf_is_connected
```c
bool bt_hfp_hf_is_connected(bt_instance_t* ins, bt_address_t* addr);
```
Check whether the HFP HF profile is connected to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns true if connected, or false otherwise.
### bt_hfp_hf_is_audio_connected
```c
bool bt_hfp_hf_is_audio_connected(bt_instance_t* ins, bt_address_t* addr);
```
Check whether the SCO audio connection is established with the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns true if audio is connected, or false otherwise.
### bt_hfp_hf_get_connection_state
```c
profile_connection_state_t bt_hfp_hf_get_connection_state(bt_instance_t* ins, bt_address_t* addr);
```
Get the current HFP HF connection state with the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns the current profile connection state.
### bt_hfp_hf_connect
```c
bt_status_t bt_hfp_hf_connect(bt_instance_t* ins, bt_address_t* addr);
```
Initiate an HFP HF connection to a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_disconnect
```c
bt_status_t bt_hfp_hf_disconnect(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the HFP HF connection from a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_set_connection_policy
```c
bt_status_t bt_hfp_hf_set_connection_policy(bt_instance_t* ins, bt_address_t* addr, connection_policy_t policy);
```
Set the HFP HF connection policy for a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `policy` Connection policy value.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_connect_audio
```c
bt_status_t bt_hfp_hf_connect_audio(bt_instance_t* ins, bt_address_t* addr);
```
Establish a SCO audio connection with a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_disconnect_audio
```c
bt_status_t bt_hfp_hf_disconnect_audio(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the SCO audio connection from a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_start_voice_recognition
```c
bt_status_t bt_hfp_hf_start_voice_recognition(bt_instance_t* ins, bt_address_t* addr);
```
Start voice recognition on the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_stop_voice_recognition
```c
bt_status_t bt_hfp_hf_stop_voice_recognition(bt_instance_t* ins, bt_address_t* addr);
```
Stop voice recognition on the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_dial
```c
bt_status_t bt_hfp_hf_dial(bt_instance_t* ins, bt_address_t* addr, const char* number);
```
Initiate a call via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `number` Phone number to dial.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_dial_memory
```c
bt_status_t bt_hfp_hf_dial_memory(bt_instance_t* ins, bt_address_t* addr, uint32_t memory);
```
Dial a number stored in memory via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `memory` Memory location index.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_redial
```c
bt_status_t bt_hfp_hf_redial(bt_instance_t* ins, bt_address_t* addr);
```
Redial the last dialed number via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_accept_call
```c
bt_status_t bt_hfp_hf_accept_call(bt_instance_t* ins, bt_address_t* addr, hfp_call_accept_t flag);
```
Accept an incoming call via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `flag` Call accept flag.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_reject_call
```c
bt_status_t bt_hfp_hf_reject_call(bt_instance_t* ins, bt_address_t* addr);
```
Reject an incoming call via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_hold_call
```c
bt_status_t bt_hfp_hf_hold_call(bt_instance_t* ins, bt_address_t* addr);
```
Hold the current call via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_terminate_call
```c
bt_status_t bt_hfp_hf_terminate_call(bt_instance_t* ins, bt_address_t* addr);
```
Terminate the current call via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_control_call
```c
bt_status_t bt_hfp_hf_control_call(bt_instance_t* ins, bt_address_t* addr, hfp_call_control_t chld, uint8_t index);
```
Control call state via HFP CHLD command.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `chld` CHLD command type.
- `index` Call index.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_query_current_calls
```c
bt_status_t bt_hfp_hf_query_current_calls(bt_instance_t* ins, bt_address_t* addr, hfp_current_call_t** calls, int* num, bt_allocator_t allocator);
```
Query the status of all current calls (CLCC).
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `calls` Output parameter, stores the call information array.
- `num` Output parameter, stores the number of calls.
- `allocator` Memory allocator function.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_send_at_cmd
```c
bt_status_t bt_hfp_hf_send_at_cmd(bt_instance_t* ins, bt_address_t* addr, const char* cmd);
```
Send a custom AT command to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `cmd` AT command string.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_update_battery_level
```c
bt_status_t bt_hfp_hf_update_battery_level(bt_instance_t* ins, bt_address_t* addr, uint8_t level);
```
Update the local battery level information to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `level` Battery level value.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_volume_control
```c
bt_status_t bt_hfp_hf_volume_control(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume);
```
Control the volume on the remote device via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `type` Volume type (speaker or microphone).
- `volume` Volume level.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_send_dtmf
```c
bt_status_t bt_hfp_hf_send_dtmf(bt_instance_t* ins, bt_address_t* addr, char dtmf);
```
Send a DTMF tone via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `dtmf` DTMF key character.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_hf_get_subscriber_number
```c
bt_status_t bt_hfp_hf_get_subscriber_number(bt_instance_t* ins, bt_address_t* addr);
```
Get the subscriber number from the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
### bt_hfp_hf_query_current_calls_with_callback
```c
bt_status_t bt_hfp_hf_query_current_calls_with_callback(bt_instance_t* ins, bt_address_t* addr);
```
Query the status of all current calls (CLCC), with results returned via callback.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
### bt_hfp_ag_unregister_callbacks
```c
bool bt_hfp_ag_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister callback functions and stop receiving state change notifications.
**Parameters**:
- `cookie` User context.
- `ins` Bluetooth client instance.
**Returns**:
Returns true on success, or false on failure.
### bt_hfp_ag_is_connected
```c
bool bt_hfp_ag_is_connected(bt_instance_t* ins, bt_address_t* addr);
```
Check whether the HFP AG profile is connected to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns true if connected, or false otherwise.
### bt_hfp_ag_is_audio_connected
```c
bool bt_hfp_ag_is_audio_connected(bt_instance_t* ins, bt_address_t* addr);
```
Check whether the SCO audio connection is established with the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns true if audio is connected, or false otherwise.
### bt_hfp_ag_get_connection_state
```c
profile_connection_state_t bt_hfp_ag_get_connection_state(bt_instance_t* ins, bt_address_t* addr);
```
Get the current HFP AG connection state with the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns the current profile connection state.
### bt_hfp_ag_connect
```c
bt_status_t bt_hfp_ag_connect(bt_instance_t* ins, bt_address_t* addr);
```
Initiate an HFP AG connection to a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_disconnect
```c
bt_status_t bt_hfp_ag_disconnect(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the HFP AG connection from a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_connect_audio
```c
bt_status_t bt_hfp_ag_connect_audio(bt_instance_t* ins, bt_address_t* addr);
```
Establish a SCO audio connection with a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_disconnect_audio
```c
bt_status_t bt_hfp_ag_disconnect_audio(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the SCO audio connection from a remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_start_virtual_call
```c
bt_status_t bt_hfp_ag_start_virtual_call(bt_instance_t* ins, bt_address_t* addr);
```
Start a virtual call on the AG side.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_stop_virtual_call
```c
bt_status_t bt_hfp_ag_stop_virtual_call(bt_instance_t* ins, bt_address_t* addr);
```
Stop a virtual call on the AG side.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_start_voice_recognition
```c
bt_status_t bt_hfp_ag_start_voice_recognition(bt_instance_t* ins, bt_address_t* addr);
```
Start voice recognition on the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_stop_voice_recognition
```c
bt_status_t bt_hfp_ag_stop_voice_recognition(bt_instance_t* ins, bt_address_t* addr);
```
Stop voice recognition on the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_phone_state_change
```c
bt_status_t bt_hfp_ag_phone_state_change(bt_instance_t* ins, bt_address_t* addr, uint8_t num_active, uint8_t num_held, hfp_ag_call_state_t call_state, hfp_call_addrtype_t type, const char* number, const char* name);
```
Notify the remote device of a phone state change (incoming call, active call, hang up, etc.).
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `num_active` Number of active calls.
- `num_held` Number of held calls.
- `call_state` Call state.
- `type` Address type.
- `number` Phone number.
- `name` Caller name.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_notify_device_status
```c
bt_status_t bt_hfp_ag_notify_device_status(bt_instance_t* ins, bt_address_t* addr, hfp_network_state_t network, hfp_roaming_state_t roam, uint8_t signal, uint8_t battery);
```
Notify the remote device of the current device status.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `network` Network state.
- `roam` Roaming state.
- `signal` Signal strength.
- `battery` Battery level.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_volume_control
```c
bt_status_t bt_hfp_ag_volume_control(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume);
```
Control the volume on the remote device via HFP.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `type` Volume type (speaker or microphone).
- `volume` Volume level.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_send_at_command
```c
bt_status_t bt_hfp_ag_send_at_command(bt_instance_t* ins, bt_address_t* addr, const char* at_command);
```
Send an AT command to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `at_command` AT command string.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_send_vendor_specific_at_command
```c
bt_status_t bt_hfp_ag_send_vendor_specific_at_command(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value);
```
Send a vendor-specific AT command to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `command` Vendor-specific command.
- `value` Command value.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_send_clcc_response
```c
bt_status_t bt_hfp_ag_send_clcc_response(bt_instance_t* ins, bt_address_t* addr, uint32_t index, hfp_call_direction_t dir, hfp_ag_call_state_t state, hfp_call_mode_t mode, hfp_call_mpty_type_t mpty, hfp_call_addrtype_t type, const char* number);
```
Send a CLCC response to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `index` Call index.
- `dir` Call direction (incoming/outgoing).
- `state` Call state.
- `mode` Call mode.
- `mpty` Whether the call is a multiparty call.
- `type` Address type.
- `number` Phone number.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hfp_ag_send_cind_response
```c
bt_status_t bt_hfp_ag_send_cind_response(bt_instance_t* ins, bt_address_t* addr, hfp_network_state_t network, hfp_call_t call, hfp_callheld_t call_held, hfp_callsetup_t call_setup, uint8_t signal, hfp_roaming_state_t roam, uint8_t battery);
```
Send a CIND response to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `network` Network state.
- `call` Call information.
- `call_held` Number of held calls.
- `call_setup` Call setup state.
- `signal` Signal strength.
- `roam` Roaming state.
- `battery` Battery level.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.

View File

@ -1,177 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_hid.md) \]
# Bluetooth HID API
The openvela Bluetooth HID (Human Interface Device) interface supports input devices such as keyboards, mice, and game controllers.
Header file: #include "bt_hid_device.h"
## openvela Implementation Notes
- **Device role**: HID Device (input device side)
## Synchronous Interfaces
### bt_hid_device_unregister_callbacks
```c
bool bt_hid_device_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister callback functions and stop receiving state change notifications.
**Parameters**:
- `cookie` User context.
- `ins` Bluetooth client instance.
**Returns**:
Returns the callback cookie on success, or NULL on failure.
### bt_hid_device_register_app
```c
bt_status_t bt_hid_device_register_app(bt_instance_t* ins, hid_device_sdp_settings_t* sdp_setting, bool le_hid);
```
Register an HID device application.
**Parameters**:
- `ins` Bluetooth client instance.
- `sdp_setting` SDP settings.
- `le_hid` Whether this is a LE HID instance.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or a negated error code on failure.
### bt_hid_device_unregister_app
```c
bt_status_t bt_hid_device_unregister_app(bt_instance_t* ins);
```
Unregister the HID device application.
**Parameters**:
- `ins` Bluetooth client instance.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_hid_device_connect
```c
bt_status_t bt_hid_device_connect(bt_instance_t* ins, bt_address_t* addr);
```
Initiate a connection to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or a negated error code on failure.
### bt_hid_device_disconnect
```c
bt_status_t bt_hid_device_disconnect(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect from the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or a negated error code on failure.
### bt_hid_device_send_report
```c
bt_status_t bt_hid_device_send_report(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_id, uint8_t* rpt_data, int rpt_size);
```
Send an HID input report to the connected host.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `rpt_id` HID report ID.
- `rpt_data` HID report data.
- `rpt_size` Report data size in bytes.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or a negated error code on failure.
### bt_hid_device_response_report
```c
bt_status_t bt_hid_device_response_report(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_type, uint8_t* rpt_data, int rpt_size);
```
Respond to a host HID report request.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `rpt_type` HID report type (input/output/feature).
- `rpt_data` HID report data.
- `rpt_size` Report data size in bytes.
### bt_hid_device_report_error
```c
bt_status_t bt_hid_device_report_error(bt_instance_t* ins, bt_address_t* addr, hid_status_error_t error);
```
Report an HID error to the host.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `error` Error code.
### bt_hid_device_virtual_unplug
```c
bt_status_t bt_hid_device_virtual_unplug(bt_instance_t* ins, bt_address_t* addr);
```
Send a virtual unplug request to disconnect the HID connection.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.

View File

@ -1,73 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_pan.md) \]
# Bluetooth PAN API
The openvela Bluetooth PAN (Personal Area Network) interface supports network sharing over Bluetooth.
Header file: #include "bt_pan.h"
## openvela Implementation Notes
- **Features**: Network tethering, Bluetooth networking
## Synchronous Interfaces
### bt_pan_unregister_callbacks
```c
bool bt_pan_unregister_callbacks(bt_instance_t* ins, void* cookie);
```
Unregister callback functions and stop receiving state change notifications.
**Parameters**:
- `cookie` User context.
- `ins` Bluetooth client instance.
**Returns**:
Returns the callback cookie on success, or NULL on failure.
### bt_pan_connect
```c
bt_status_t bt_pan_connect(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role);
```
Initiate a PAN connection to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
- `dst_role` Destination device role.
- `src_role` Local device role.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_pan_disconnect
```c
bt_status_t bt_pan_disconnect(bt_instance_t* ins, bt_address_t* addr);
```
Disconnect the PAN connection from the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `addr` Bluetooth address of the remote device.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.

View File

@ -1,134 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/bt_spp.md) \]
# Bluetooth SPP API
The openvela Bluetooth SPP (Serial Port Profile) interface provides virtual serial port communication as a replacement for physical serial ports.
Header file: #include "bt_spp.h"
## openvela Implementation Notes
- **Features**: Virtual serial port communication, suitable for Bluetooth-enabling traditional serial devices
## Synchronous Interfaces
### bt_spp_unregister_app
```c
bt_status_t bt_spp_unregister_app(bt_instance_t* ins, void* handle);
```
Unregister an SPP application.
**Parameters**:
- `handle` Application handle.
- `ins` Bluetooth client instance.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_spp_server_start
```c
bt_status_t bt_spp_server_start(bt_instance_t* ins, void* handle, uint16_t scn, bt_uuid_t* uuid, uint8_t max_connection);
```
Start an SPP server to listen for connection requests from remote devices.
**Parameters**:
- `ins` Bluetooth client instance.
- `handle` Application handle.
- `scn` Server channel number.
- `uuid` Service UUID.
- `max_connection` Maximum number of connections.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_spp_server_stop
```c
bt_status_t bt_spp_server_stop(bt_instance_t* ins, void* handle, uint16_t scn);
```
Stop the SPP server and stop accepting new connections.
**Parameters**:
- `ins` Bluetooth client instance.
- `handle` Application handle.
- `scn` Server channel number.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_spp_connect
```c
bt_status_t bt_spp_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port);
```
Initiate a connection to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `handle` Application handle.
- `addr` Bluetooth address of the remote device.
- `scn` Server channel number.
- `uuid` Service UUID.
- `port` Port number.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.
### bt_spp_insecure_connect
```c
bt_status_t bt_spp_insecure_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port);
```
Initiate an insecure connection to the remote device.
**Parameters**:
- `ins` Bluetooth client instance.
- `handle` Application handle.
- `addr` Bluetooth address of the remote device.
- `scn` Server channel number.
- `uuid` Service UUID.
- `port` Port number.
### bt_spp_disconnect
```c
bt_status_t bt_spp_disconnect(bt_instance_t* ins, void* handle, bt_address_t* addr, uint16_t port);
```
Disconnect the SPP connection.
**Parameters**:
- `ins` Bluetooth client instance.
- `handle` Application handle.
- `addr` Bluetooth address of the peer device.
- `port` Port number.
**Returns**:
Returns BT_STATUS_SUCCESS on success, or an error code on failure.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,26 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/bluetooth/index.md) \]
# Bluetooth API
The openvela Bluetooth framework provides a complete Bluetooth stack interface, supporting Classic Bluetooth (BR/EDR) and Bluetooth Low Energy (BLE), covering everything from low-level connection management to upper-layer application profiles.
## Core Protocols
- **[GAP](bt_gap.md)** (Generic Access Profile) — Device discovery, connection management, pairing and security
- **[GATT](bt_gatt.md)** (Generic Attribute Profile) — BLE data attribute read/write and notifications
- **[Device Management](bt_device.md)** — Remote device pairing, connection, and property queries
## Audio and Media
- **[A2DP](bt_a2dp.md)** (Advanced Audio Distribution Profile) — High-quality stereo music streaming
- **[HFP](bt_hfp.md)** (Hands-Free Profile) — Bluetooth call functionality
## Positioning and Ranging
- **[CS](bt_cs.md)** (Channel Sounding) — Bluetooth channel sounding for distance measurement and positioning
## Data and Peripherals
- **[HID](bt_hid.md)** (Human Interface Device) — Keyboards, mice, game controllers
- **[SPP](bt_spp.md)** (Serial Port Profile) — Data pass-through
- **[PAN](bt_pan.md)** (Personal Area Network) — Network sharing and Bluetooth networking

View File

@ -1,151 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/feature_framework.md) \]
# Feature Framework Overview
## Feature Framework Introduction
In QuickApp development, new capabilities need to be added to QuickApps, and these capabilities are written in C/C++. The Feature framework is a framework, SDK, and toolset that helps system developers extend functionality for QuickApps.
The overall architecture is organized into the following layers, from top to bottom:
- **JS Layer** — QuickApp (user JS code)
- **Framework Layer** — QuickApp Framework (together with the QuickApp Engine) and Feature Framework
- **Native Layer** — Feature implementations written in C/C++
- **OS Layer** — openvela
## Feature Framework Capabilities
The Feature framework consists of a runtime framework, APIs, and the JIDL language and tools:
- Provides an execution framework for JS layer to call Native code
- The Feature framework API provides a set of interfaces for Native code to interact with JS
- JIDL is an interface description language used to automatically generate interfaces for mutual invocation between JS and Native
<img src="./figures/JIDL.png" alt="JIDL Interface Description Language Workflow" style="zoom:50%;" />
### Feature Concept Model
#### Static Concept Model
Since Features provide interfaces from Native to JS, the Feature concepts also follow JS conventions.
Features have 3 conceptual layers:
- Module: A Feature is a module, equivalent to a program module in C. It has no instances and exists globally.
- Prototype: Equivalent to a prototype object in JS, similar to a class in C++ but with differences. One QuickApp instance produces one Prototype. All functions and properties on a Feature are managed on the Prototype.
- Instance: One app contains multiple instances (each `require` produces an instance). Instances hold all processing data.
Specifically in QuickApps:
- A QuickApp instance has only one Prototype.
- A QuickApp page typically contains only one Feature Instance.
From a system perspective, the Feature concepts:
<img src="./figures/feature_static.png" alt="Feature Static Concept Model" style="zoom: 67%;" />
#### Runtime Concept Model
Each Feature can associate Native data, with different associated content:
- **Module** is purely internal to the Native side and is never exposed to the JS environment.
- **Prototype** appears in JS as a `JSObject`, but cannot be used directly from JS. On the Native side, it holds `prototype Native data` whose lifetime matches the app.
- **Instance** also appears in JS as a `JSObject`, and on the Native side holds `instance Native data` whose lifetime matches the instance itself.
#### Feature Lifecycle
The Feature lifecycle consists of six events, listed below in the order they occur:
| Event | Triggered When | Notes |
| ---------------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **`onRegister`** (Module Registration) | When the system starts up, or when `FeatureManagerRegister` is called | Do not perform long / complex tasks during registration, otherwise system startup will slow down |
| **`onCreate`** (Prototype Creation) | The first time the app uses the Feature | Do not expect this function to be called at app startup |
| **`onRequire`** (Instance Creation) | When the app calls `require` for this Feature | Feature instance initialization can be done here |
| **`onDettach`** (Instance Destruction) | When a Feature instance is destroyed (page exit, app exit, etc.) | Feature teardown is non-deterministic; do not defer recycling of temporary data to this point |
| **`onDestroy`** (Prototype Destruction) | When the app exits | App-wide global data is recycled here |
| **`onUnregister`** (Module Unregistered) | When the Feature is unregistered | Do not rely on this callback; it may never be called |
### Feature Framework Interface Capabilities
#### Automatic Generation of Feature Prototype and Instance
The Feature framework helps developers create Feature Prototypes and Instances.
1. Feature developers need to provide a FeatureDescription that describes the Feature information, including:
- Feature name
- Feature member composition
- Methods supported by the Feature, including method name, parameter list, return value, and implementation callback function
- Property name, type, and implementation function
- Others
2. Based on the FeatureDescription, FeaturePrototype and FeatureInstance are generated, and provided to developers as `FeatureProtoHandle` and `FeatureInstanceHandle`.
<img src="./figures/feature_instance.png" alt="Feature Instance Creation Flow" style="zoom: 50%;" />
#### Parameter Conversion
From JS to Native, the Feature framework provides parameter conversion capabilities, converting JS parameters to plain parameters. The following table shows the basic conversion capabilities:
| JS Type | C Type | Description |
| -------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| number/boolean | int, float, double, bool | JS number types exist as floating point. Based on JIDL description, they can be converted to compatible types like int, float. Converting to int/bool causes loss of decimal part |
| string | FtString | `const char*` typedef |
| object | struct pointer / FtAny pointer | If a struct is defined in JIDL, converts to the corresponding C struct pointer; if defined as object/any type in JIDL, defined as FtAny pointer |
| array | FtArray pointer | Converts to a C structure FtArray |
| function | FtCallbackId | Converts to an integer representing CallbackId |
| promise | FtPromiseId | Converts to an integer representing PromiseId |
---
- Pointer objects have built-in reference counting and can be released via `FeatureDupValue` and `FeatureFreeValue`.
- Pointers passed through parameters do not need additional release.
The Feature framework internally manages Callback and Promise objects, hiding the implementation details:
- Feature developers receive opaque IDs (`FtCallbackId` / `FtPromiseId`) instead of direct references to JS Function or Promise objects.
- The real JS Function and Promise instances are held inside the Feature framework (not visible to developers), together with reference counting.
- IDs act as indices into the internal tables, and the framework is responsible for reclaiming them.
The Feature framework achieves two goals by hiding details:
- Feature developers do not need to care about details or manage the lifecycle of Callbacks and Promises.
- FeatureInstance provides fallback memory management methods.
#### Asynchronous Programming Model
Feature code and JS code run in the same uvloop. Feature developers need to be mindful of call duration. Blocking is not allowed in regular functions.
<img src="./figures/Asynchronous_model.png" alt="Asynchronous Programming Model Diagram" style="zoom:50%;" />
- A task can be added to the worker queue.
- Any thread can call `FeaturePost` to add a task to the main loop queue.
### JIDL Interface Description
JIDL is used to describe Feature interfaces. Below is a simple Feature file:
```C++
// Module name
module test@1.0
callback cb(int a, int b);
void foo(int a, float b, string c);
void goo(int a, cb cb1);
property string name;
property int age;
```
- Uses C++-style comments.
- Always starts with `module`, including module name and version.
- Can define properties, functions, interfaces, etc.
File naming conventions:
- File names end with `.jidl`.
- File names are typically `<feature name>_<version>.jidl`, but this is not mandatory.
Module naming allows the use of `.` separator, such as `system.fetch`.

View File

@ -1,741 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/feature_framework_context.md) \]
# Feature Context API
Unified data type and context operation interfaces provided by the Feature framework. By wrapping frontend (QuickJS, WAMR, etc.) native objects through `ft_value_t`, developers can perform type conversion, array/object operations, and memory management without being aware of specific frontend differences.
Header: `#include <feature_context.h>`
## openvela Implementation Notes
- **Core data type `ft_value_t`**: Uniformly wraps frontend JSValue/Wasm objects, using 16-byte or 8-byte storage depending on whether the target platform is 64-bit
- **`ft_context_ref`**: A context object that accompanies `ft_value_t`; all APIs require it to locate the specific frontend runtime
- **Value types vs reference types**:
- `ft_from_int` / `ft_from_bool` etc. return value types that do not require explicit release
- `ft_from_string` / `ft_from_buffer` / `ft_new_object` etc. return reference types that must be released via `ft_free_value`
- **Release rules**:
- **No release needed**: `ft_value_t` parameters received by Feature implementation functions, `ft_value_t` returned to the frontend as return values
- **Must release**: Objects created by `ft_from_xxx`, objects created by `ft_new_object`, elements retrieved by `ft_array_at`, properties returned by `ft_obj_get_property`, results from `ft_parse_json`
- Strings: `const char*` returned by `ft_to_string` must be released with `ft_free_string`
## Feature Context and Frontend Runtime
The diagram below shows how the Feature framework uses `ft_value_t` and `ft_context_ref` to uniformly wrap native objects of frontend runtimes (using QuickJS as an example):
![Feature Context and Frontend Runtime](figures/ft_context.svg)
- **Feature Framework Interface**: The unified C interface exposed by the Feature framework, consisting of `ft_value_t` (data) and `ft_context_ref` (context).
- **JS Implementation**: The concrete frontend runtime implementation. `ft_value_t` maps to `JSValue`, and `ft_context_ref` maps to `JSContext`, with an N:1 relationship between them (multiple values belong to the same context).
- When switching to another frontend (for example, WAMR), the Feature implementation code does not need to change; only the underlying mapping needs to be replaced.
## Type and Context Access
### ft_context_get_data
```c
void* ft_context_get_data(ft_context_ref ft_ctx);
```
Retrieves the user data pointer associated with the current Feature context. This user data is bound by the Feature manager during initialization.
**Parameters**:
- `ft_ctx` Current Feature context reference.
**Returns**:
Returns the associated user data pointer, or `NULL` if not bound.
### ft_get_type
```c
ft_type ft_get_type(ft_context_ref ft_ctx, ft_value_t ft_val);
```
Gets the type of a given `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `ft_val` The `ft_value_t` whose type is to be queried.
**Returns**:
Returns the type enum `ft_type`:
- `FT_TYPE_NULL`: null
- `FT_TYPE_UNDEF`: undefined
- `FT_TYPE_NONE`: undefined value
- `FT_TYPE_NUMBER`: number
- `FT_TYPE_BOOL`: boolean
- `FT_TYPE_STRING`: string
- `FT_TYPE_ARRAY`: array
- `FT_TYPE_BUFFER`: binary buffer
- `FT_TYPE_TYPED_BUFFER`: typed buffer
- `FT_TYPE_OBJECT`: object
### ft_undefined
```c
ft_value_t ft_undefined(ft_context_ref ft_ctx);
```
Constructs an undefined-type `ft_value_t`. Used to return a "no value" result to the frontend.
**Parameters**:
- `ft_ctx` Current Feature context reference.
**Returns**:
Returns an `ft_value_t` of type `FT_TYPE_UNDEF`. This is a value type and does not require explicit release.
## Type Conversion from Primitive Types (Native to ft_value_t)
The following interfaces convert C native types to `ft_value_t` for passing to the frontend.
### ft_from_int
```c
ft_value_t ft_from_int(ft_context_ref ft_ctx, int32_t val);
```
Converts a 32-bit signed integer to `ft_value_t`. The return value is a value type and does not require release.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` 32-bit signed integer value.
**Returns**:
Returns the corresponding `ft_value_t` (type `FT_TYPE_NUMBER`).
### ft_from_uint
```c
ft_value_t ft_from_uint(ft_context_ref ft_ctx, uint32_t val);
```
Converts a 32-bit unsigned integer to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` 32-bit unsigned integer value.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_int64
```c
ft_value_t ft_from_int64(ft_context_ref ft_ctx, int64_t val);
```
Converts a 64-bit signed integer to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` 64-bit signed integer value.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_uint64
```c
ft_value_t ft_from_uint64(ft_context_ref ft_ctx, uint64_t val);
```
Converts a 64-bit unsigned integer to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` 64-bit unsigned integer value.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_double
```c
ft_value_t ft_from_double(ft_context_ref ft_ctx, double val);
```
Converts a double-precision floating-point number to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Double-precision floating-point value.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_bool
```c
ft_value_t ft_from_bool(ft_context_ref ft_ctx, bool val);
```
Converts a boolean value to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Boolean value.
**Returns**:
Returns the corresponding `ft_value_t` (type `FT_TYPE_BOOL`).
### ft_from_string
```c
ft_value_t ft_from_string(ft_context_ref ft_ctx, const char* val);
```
Converts a C string to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Null-terminated C string.
**Returns**:
Returns the corresponding `ft_value_t` (type `FT_TYPE_STRING`).
**Notes**:
- The returned `ft_value_t` is a reference type and **must** be released via `ft_free_value`.
- The implementation copies the content of `val`; the original pointer can be freed immediately after the call.
## Binary Buffer Conversion
### ft_from_buffer
```c
ft_value_t ft_from_buffer(ft_context_ref ft_ctx, uint8_t* buff, uint32_t size);
```
Wraps a native byte buffer into an `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `buff` Pointer to the start of the byte buffer.
- `size` Number of bytes in the buffer.
**Returns**:
Returns the corresponding `ft_value_t` (type `FT_TYPE_BUFFER`).
**Notes**:
- The returned `ft_value_t` is a reference type and must be released via `ft_free_value`.
### ft_from_typed_buffer
```c
ft_value_t ft_from_typed_buffer(ft_context_ref ft_ctx, uint8_t* buff,
uint32_t size, FtTypedArrayType type);
```
Wraps a native buffer into a frontend Typed Array.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `buff` Pointer to the start of the byte buffer.
- `size` Number of bytes in the buffer.
- `type` Element type of the typed array, see `FtTypedArrayType`:
- `FT_Int8Array` / `FT_Uint8Array`
- `FT_Int16Array` / `FT_Uint16Array`
- `FT_Int32Array` / `FT_Uint32Array`
- `FT_Float32Array` / `FT_Float64Array`
**Returns**:
Returns the corresponding `ft_value_t` (type `FT_TYPE_TYPED_BUFFER`). Must be released via `ft_free_value`.
**Example**:
```c
uint8_t* buff = ft_to_buffer(ft_ctx, &size, data);
// Process buff
ft_value_t ret = ft_from_typed_buffer(ft_ctx, buff, size, FT_Uint8Array);
```
### ft_parse_json
```c
ft_value_t ft_parse_json(ft_context_ref ft_ctx, const char* buf,
size_t buf_len, const char* filename);
```
Parses a JSON string into an `ft_value_t` object.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `buf` Pointer to the JSON string.
- `buf_len` Length of the JSON string in bytes.
- `filename` Filename used for error location, can be `NULL`.
**Returns**:
Returns the parsed `ft_value_t` on success; returns a value of type `FT_TYPE_UNDEF` on failure.
**Notes**:
- The returned `ft_value_t` is a reference type and must be released via `ft_free_value`.
## Array Type Conversion (Native Array to ft_value_t)
Converts native arrays to `ft_value_t` arrays. All return values are reference types and must be released via `ft_free_value`.
### ft_from_int_array
```c
ft_value_t ft_from_int_array(ft_context_ref ft_ctx, int32_t* val, uint32_t size);
```
Converts an int32 array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Source array pointer.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t` (type `FT_TYPE_ARRAY`).
### ft_from_uint_array
```c
ft_value_t ft_from_uint_array(ft_context_ref ft_ctx, uint32_t* val, uint32_t size);
```
Converts a uint32 array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Source array pointer.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_int64_array
```c
ft_value_t ft_from_int64_array(ft_context_ref ft_ctx, int64_t* val, uint32_t size);
```
Converts an int64 array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Source array pointer.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_uint64_array
```c
ft_value_t ft_from_uint64_array(ft_context_ref ft_ctx, uint64_t* val, uint32_t size);
```
Converts a uint64 array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Source array pointer.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_bool_array
```c
ft_value_t ft_from_bool_array(ft_context_ref ft_ctx, bool* val, uint32_t size);
```
Converts a boolean array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Source array pointer.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_double_array
```c
ft_value_t ft_from_double_array(ft_context_ref ft_ctx, double* val, uint32_t size);
```
Converts a double array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Source array pointer.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t`.
### ft_from_string_array
```c
ft_value_t ft_from_string_array(ft_context_ref ft_ctx, const char** val, uint32_t size);
```
Converts a C string array to `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `val` Array of string pointers.
- `size` Number of array elements.
**Returns**:
Returns the corresponding `ft_value_t`.
## Type Conversion to Primitive Types (ft_value_t to Native)
The following interfaces convert `ft_value_t` passed from the frontend to C native types for use in Feature implementations.
### ft_to_int
```c
bool ft_to_int(ft_context_ref ft_ctx, ft_value_t f_val, int32_t* val);
```
Converts an `ft_value_t` to a 32-bit signed integer.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `f_val` Source `ft_value_t`, should be a numeric type.
- `val` Pointer to `int32_t` to receive the result.
**Returns**:
Returns `true` on successful conversion, `false` otherwise (typically because `f_val` is not a numeric type).
### ft_to_uint
```c
bool ft_to_uint(ft_context_ref ft_ctx, ft_value_t f_val, uint32_t* val);
```
Converts an `ft_value_t` to a 32-bit unsigned integer.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `f_val` Source `ft_value_t`.
- `val` Pointer to `uint32_t` to receive the result.
**Returns**:
Returns `true` on success, `false` on failure.
### ft_to_int64
```c
bool ft_to_int64(ft_context_ref ft_ctx, ft_value_t f_val, int64_t* val);
```
Converts an `ft_value_t` to a 64-bit signed integer.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `f_val` Source `ft_value_t`.
- `val` Pointer to `int64_t` to receive the result.
**Returns**:
Returns `true` on success, `false` on failure.
### ft_to_uint64
```c
bool ft_to_uint64(ft_context_ref ft_ctx, ft_value_t f_val, uint64_t* val);
```
Converts an `ft_value_t` to a 64-bit unsigned integer.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `f_val` Source `ft_value_t`.
- `val` Pointer to `uint64_t` to receive the result.
**Returns**:
Returns `true` on success, `false` on failure.
### ft_to_double
```c
bool ft_to_double(ft_context_ref ft_ctx, ft_value_t f_val, double* val);
```
Converts an `ft_value_t` to a double-precision floating-point number.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `f_val` Source `ft_value_t`.
- `val` Pointer to `double` to receive the result.
**Returns**:
Returns `true` on success, `false` on failure.
### ft_to_bool
```c
bool ft_to_bool(ft_context_ref ft_ctx, ft_value_t ft_val, bool* val);
```
Converts an `ft_value_t` to a boolean value.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `ft_val` Source `ft_value_t`.
- `val` Pointer to `bool` to receive the result.
**Returns**:
Returns `true` on success, `false` on failure.
### ft_to_string
```c
const char* ft_to_string(ft_context_ref ft_ctx, ft_value_t f_val);
```
Converts an `ft_value_t` to a C string.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `f_val` Source `ft_value_t`, should be a string type.
**Returns**:
Returns the string pointer on success; returns `NULL` on failure.
**Notes**:
- The returned string is managed by the framework and **must** be released via `ft_free_string`.
- The Feature framework does not guarantee the string remains valid long-term; copy it promptly if you need to retain it.
### ft_to_buffer
```c
uint8_t* ft_to_buffer(ft_context_ref ft_ctx, size_t* p_size, ft_value_t f_val);
```
Converts an `ft_value_t` to a binary buffer.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `p_size` Output parameter that returns the number of bytes in the buffer.
- `f_val` Source `ft_value_t`, should be `FT_TYPE_BUFFER` or `FT_TYPE_TYPED_BUFFER`.
**Returns**:
Returns the buffer start pointer on success; returns `NULL` on failure.
**Notes**:
- The returned pointer is managed by the frontend; do not manually `free` it.
## Array Operations
### ft_array_size
```c
uint32_t ft_array_size(ft_context_ref ft_ctx, const ft_value_t array);
```
Gets the number of elements in an `ft_value_t` array.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `array` An `ft_value_t` of array type.
**Returns**:
Returns the number of array elements. Returns 0 if `array` is not an array type.
### ft_array_at
```c
ft_value_t ft_array_at(ft_context_ref ft_ctx, const ft_value_t array, uint32_t idx);
```
Accesses an element in an `ft_value_t` array by index.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `array` An `ft_value_t` of array type.
- `idx` Element index, starting from 0.
**Returns**:
Returns the element `ft_value_t` at the given index on success; returns undefined if out of bounds or `array` is not an array.
**Notes**:
- The returned `ft_value_t` is a reference type and **must** be released via `ft_free_value`.
## Object Operations
### ft_new_object
```c
ft_value_t ft_new_object(ft_context_ref ft_ctx);
```
Creates an empty `ft_value_t` object. Features can attach custom properties to this object.
**Parameters**:
- `ft_ctx` Current Feature context reference.
**Returns**:
Returns the newly created object `ft_value_t` (type `FT_TYPE_OBJECT`).
**Notes**:
- The return value is a reference type and must be released via `ft_free_value`.
- The object supports attaching child properties; child properties are automatically released when the root object is released.
### ft_obj_get_property
```c
ft_value_t ft_obj_get_property(ft_context_ref ft_ctx, ft_value_t ft_val, const char* prop);
```
Reads a property value from an `ft_value_t` object by property name.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `ft_val` An `ft_value_t` of object type.
- `prop` Property name.
**Returns**:
Returns the property value `ft_value_t` on success; returns undefined if the property does not exist.
**Notes**:
- The returned `ft_value_t` is a reference type and must be released via `ft_free_value`.
### ft_obj_set_property
```c
bool ft_obj_set_property(ft_context_ref ft_ctx, ft_value_t obj,
const char* prop, ft_value_t val);
```
Sets a property value on an `ft_value_t` object.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `obj` Target object `ft_value_t`.
- `prop` Property name.
- `val` Property value to set.
**Returns**:
Returns `true` on success, `false` on failure.
## Memory Management
### ft_free_value
```c
void ft_free_value(ft_context_ref ft_ctx, ft_value_t ft_val);
```
Releases the reference count of an `ft_value_t`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `ft_val` The `ft_value_t` to release.
**Notes**:
`ft_value_t` sources that **require release**:
- Objects created by `ft_from_xxx`
- Objects created by `ft_new_object`
- Elements retrieved by `ft_array_at`
- Properties returned by `ft_obj_get_property`
- Objects parsed by `ft_parse_json`
`ft_value_t` sources that **do not require release**:
- Parameters received by Feature implementation functions
- `ft_value_t` returned to the frontend as return values
Failing to properly release reference-type `ft_value_t` will cause memory leaks.
### ft_free_string
```c
void ft_free_string(ft_context_ref ft_ctx, const char* str);
```
Releases a string returned by `ft_to_string`.
**Parameters**:
- `ft_ctx` Current Feature context reference.
- `str` String pointer to release.
**Notes**:
- The Feature framework does not guarantee that strings returned by `ft_to_string` remain valid long-term; call this interface to release them promptly after use.
- Do not use `free()` or `delete` to release; you must use this interface.

File diff suppressed because it is too large Load Diff

View File

@ -1,316 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/feature_framework_main_export.md) \]
# Feature Main Export API
Lifecycle management and global configuration interfaces for the Feature Manager. Primarily used for QuickApp framework initialization, binding the runtime event loop, registering Features, and managing permissions.
Header file: `#include <feature_main_exports.h>`
## openvela Implementation Notes
- **Usage scenario**: This set of APIs is primarily used by QuickApp framework implementors (Runtime integration layer). Feature plugin developers generally do not call these directly.
- **Relationship with Feature Manager**: One Feature Manager corresponds to one independent QuickApp instance. Created via `FeatureCreateManager`, it must be released via `FeatureFreeManager` when no longer needed.
- **Event loop integration**: Bind a libuv event loop via `FeatureSetUVLoop` to enable scheduling of asynchronous tasks. This must be completed before `FeatureCreateInstance`.
- **Permission callback mechanism**: Register a unified permission check entry via `FeatureSetPermissionsCallback`. All Feature calls requiring permissions will trigger the callback, and the caller must explicitly `Grant` or `Reject`.
## QuickApp Framework Example Code
```cpp
#ifdef CONFIG_FEATURE_FRAMEWORK
FeatureManagerCreateInfo ft_info;
ft_info.raw_ctx = (FeatureRawContextHandle)(qrt->env.ctx);
ft_info.release_cb = nullptr;
ft_info.manager_type = FEATURE_MANAGER_JS;
ft_info.package_name = app->packageName();
qrt->pFeatureMgr = FeatureCreateManager(&ft_info);
FeatureSetArgsErrorCb(qrt->pFeatureMgr, on_feature_args_error, qrt);
FeatureSetManagerUserData(qrt->pFeatureMgr, "app", app);
FeatureSetUVLoop(qrt->pFeatureMgr, qrt->loop);
#endif
```
## Manager Lifecycle
### FeatureCreateManager
```c
FeatureManagerHandle FeatureCreateManager(FeatureManagerCreateInfo* pinfo);
```
Creates a Feature Manager instance based on the given configuration.
**Parameters**:
- `pinfo` Creation configuration for the Feature Manager, containing the raw runtime context, release callback, manager type, and QuickApp package name. See `FeatureManagerCreateInfo` for details.
**Returns**:
Returns a valid `FeatureManagerHandle` on success; returns `NULL` on failure.
### FeatureFreeManager
```c
void FeatureFreeManager(FeatureManagerHandle handle);
```
Releases the Feature Manager. Before releasing, `FeatureUnsetUVLoop` should be called to unbind the event loop.
**Parameters**:
- `handle` The Feature Manager handle to release.
### FeatureUninit
```c
void FeatureUninit(FeatureManagerHandle handle);
```
Performs de-initialization on the Feature Manager. Cleans up internal state without releasing the handle itself.
**Parameters**:
- `handle` Feature Manager handle.
## Global Configuration
### FeatureSetArgsErrorCb
```c
void FeatureSetArgsErrorCb(FeatureManagerHandle handle, ArgsErrorCb cb, void* data);
```
Registers an argument error callback for the Feature Manager. When any Feature call has mismatched parameter types, this callback is triggered.
**Parameters**:
- `handle` Feature Manager handle.
- `cb` Argument error callback with signature `bool (*)(void* data, ArgsErrorInfo* args_info)`.
- `data` User data passed to the callback.
### FeatureSetPackageVersion
```c
void FeatureSetPackageVersion(FeatureManagerHandle handle, const char* package_version);
```
Sets the package version of the QuickApp corresponding to the current manager. The version can be queried via `FeatureGetPackageVersion`.
**Parameters**:
- `handle` Feature Manager handle.
- `package_version` QuickApp version string.
### FeatureSetUVLoop
```c
void FeatureSetUVLoop(FeatureManagerHandle handle, uv_loop_t* loop);
```
Binds a libuv event loop to the Feature Manager. All asynchronous tasks such as `FeaturePost` and `FeatureWorker*` will be scheduled on this loop.
**Parameters**:
- `handle` Feature Manager handle.
- `loop` libuv event loop pointer.
**Notes**:
- Must be called before `FeatureCreateInstance`.
- The same `uv_loop_t` can be shared by multiple Feature Managers, but it is generally recommended that each QuickApp instance has its own dedicated loop.
### FeatureUnsetUVLoop
```c
void FeatureUnsetUVLoop(FeatureManagerHandle handle);
```
Unbinds the libuv event loop from the Feature Manager. After unbinding, all pending asynchronous tasks become invalid.
**Parameters**:
- `handle` Feature Manager handle.
**Notes**:
- Must be called before `FeatureFreeManager`.
## Runtime Access
### FeatureManagerGetContext
```c
ft_context_ref FeatureManagerGetContext(FeatureManagerHandle handle);
```
Retrieves the Feature context reference from the Feature Manager, which can be used for `ft_value_t` related operations.
**Parameters**:
- `handle` Feature Manager handle.
**Returns**:
Returns `ft_context_ref`; returns `NULL` on failure.
### FeatureSetManagerUserData
```c
void FeatureSetManagerUserData(FeatureManagerHandle handle, const char* name, void* data);
```
Attaches user data to the Feature Manager by name. Can be used to share information across Feature instances.
**Parameters**:
- `handle` Feature Manager handle.
- `name` User data name (key).
- `data` User data pointer.
### FeatureHasFeature
```c
bool FeatureHasFeature(FeatureManagerHandle handle, FtString feature_method);
```
Checks whether a Feature with the given name is registered in the current manager.
**Parameters**:
- `handle` Feature Manager handle.
- `feature_method` The Feature name to query.
**Returns**:
Returns `true` if the Feature is registered; otherwise returns `false`.
## Feature Operations
### FeatureRequire
```c
ft_value_t FeatureRequire(FeatureManagerHandle handle,
ft_value_t binding_obj, const char* name);
```
Requests a Feature instance from the Feature Manager by name. Equivalent to `require('@system.xxx')` at the JS layer.
**Parameters**:
- `handle` Feature Manager handle.
- `binding_obj` Binding object (typically the JS global object where the Feature resides).
- `name` Feature name.
**Returns**:
Returns a `ft_value_t` wrapping the Feature instance. Returns an undefined-type `ft_value_t` on failure.
**Notes**:
- Each `FeatureRequire` call produces an independent Feature instance.
### FeatureFindFeature
```c
ft_value_t FeatureFindFeature(FeatureManagerHandle handle, const char* name);
```
Finds an already-created Feature instance without creating a new one.
**Parameters**:
- `handle` Feature Manager handle.
- `name` Feature name.
**Returns**:
Returns the `ft_value_t` corresponding to the Feature instance; returns undefined if not found.
### FeatureCreateFeature
```c
ft_value_t FeatureCreateFeature(FeatureManagerHandle handle,
ft_value_t prototype, ft_value_t binding_obj);
```
Creates a Feature instance from a prototype. Used in advanced scenarios that require direct manipulation of prototype objects.
**Parameters**:
- `handle` Feature Manager handle.
- `prototype` Feature prototype object.
- `binding_obj` Binding object.
**Returns**:
Returns the `ft_value_t` of the newly created Feature instance on success; returns undefined on failure.
## Memory Diagnostics
### FeatureDumpMemory
```c
void FeatureDumpMemory(FeatureManagerHandle feature_manager,
FeatureMemoryDump* dump, void* userdata);
```
Callback-based memory usage diagnostic interface for the Feature framework, allowing the upper layer to integrate custom memory statistics capabilities.
**Parameters**:
- `feature_manager` Feature Manager handle.
- `dump` Memory diagnostic callback structure containing `count`, `count_meta`, and `sub` callbacks. See `FeatureMemoryDump` for details.
- `userdata` User data passed through to each callback.
## Permission Management
### FeatureSetPermissionsCallback
```c
void FeatureSetPermissionsCallback(FeatureManagerHandle hmanager,
FeaturePermissionsCb cb, void* data);
```
Registers a permission check callback. When a Feature API requires permissions, the framework triggers this callback, and the business layer decides whether to grant or reject.
**Parameters**:
- `hmanager` Feature Manager handle.
- `cb` Permission check callback with signature `void (*)(FeaturePermissionsHandle, const FeaturePermissionsInfo*, void*)`.
- `data` User data passed through to the callback.
**Notes**:
- The callback must call either `FeatureGrantPermissions` or `FeatureRejectPermissions`; otherwise the corresponding Feature call will remain suspended.
### FeatureGrantPermissions
```c
void FeatureGrantPermissions(FeatureManagerHandle hmanager,
FeaturePermissionsHandle handle);
```
Grants a permission request. After calling, the corresponding Feature API call continues execution.
**Parameters**:
- `hmanager` Feature Manager handle.
- `handle` Permission request handle (passed in by the permission callback).
### FeatureRejectPermissions
```c
void FeatureRejectPermissions(FeatureManagerHandle hmanager,
FeaturePermissionsHandle handle,
FeaturePermsRejectReason reason);
```
Rejects a permission request. After calling, the corresponding Feature API call returns a permission error.
**Parameters**:
- `hmanager` Feature Manager handle.
- `handle` Permission request handle.
- `reason` Rejection reason. See `FeaturePermsRejectReason`:
- `FEATURE_PERMS_DENIED`: Permission denied
- `FEATURE_PERMS_ERROR`: Permission check error
- `FEATURE_PERMS_NO_BG`: Background calls not allowed

View File

@ -1,81 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/feature_framework_qjs_export.md) \]
# Feature QJS Export API
Interoperability interfaces between the Feature framework and the QuickJS runtime. Provides the ability to convert between `ft_value_t` and `JSValue`, available only in QuickJS frontend scenarios.
Header file: `#include <feature_qjs_exports.h>`
## openvela Implementation Notes
- **QuickJS only**: This set of interfaces can only be called under the QuickJS runtime. Do not use with other frontends such as WAMR.
- **Depends on QuickJS headers**: `feature_qjs_exports.h` internally includes `quickjs/quickjs.h`, requiring QuickJS public headers to be visible.
- **Typical usage**: When a Feature implementation needs to access QuickJS native APIs (e.g., creating objects using QuickJS-specific APIs), use these interfaces to convert between QuickJS types and the unified `ft_value_t` type of the Feature framework.
- **Not recommended for general business code**: Binding to QuickJS loses cross-runtime compatibility. Prefer the generic APIs in `feature_context.h`.
## JSValue and ft_value_t Conversion
### ft_from_jsvalue
```c
ft_value_t ft_from_jsvalue(ft_context_ref rt_ctx, JSValue val);
```
Converts a QuickJS `JSValue` to the Feature framework's `ft_value_t`.
**Parameters**:
- `rt_ctx` Current Feature context reference.
- `val` The QuickJS JSValue object to convert.
**Returns**:
Returns the corresponding `ft_value_t` object. The lifetime of the return value is managed by the Feature framework.
**Notes**:
- The caller must ensure the `JSValue` passed in is valid within the QuickJS Runtime corresponding to `rt_ctx`.
- If the returned `ft_value_t` is retained for a subsequent asynchronous context, use the relevant interfaces in `feature_context.h` to control its lifetime.
### ft_to_jsvalue
```c
JSValue ft_to_jsvalue(ft_context_ref rt_ctx, ft_value_t val);
```
Converts the Feature framework's `ft_value_t` to a QuickJS `JSValue`.
**Parameters**:
- `rt_ctx` Current Feature context reference.
- `val` The `ft_value_t` object to convert.
**Returns**:
Returns the corresponding `JSValue` object. The `JSValue` follows QuickJS's own reference counting rules, and the caller is responsible for releasing it via `JS_FreeValue` at the appropriate time.
**Notes**:
- This interface allocates the corresponding JS object within the QuickJS Runtime; the reference count is incremented by 1 before returning.
- You must call `JS_FreeValue` after use, otherwise it will cause a memory leak on the QuickJS side.
### ft_ctx_to_js_ctx
```c
JSContext* ft_ctx_to_js_ctx(ft_context_ref rt_ctx);
```
Retrieves the underlying QuickJS `JSContext*` from a Feature context reference.
**Parameters**:
- `rt_ctx` Current Feature context reference.
**Returns**:
Returns the corresponding `JSContext*` on success, which can be used directly as a parameter to QuickJS native APIs.
**Notes**:
- The returned `JSContext*` lifetime is managed by the Feature framework. **Do not** manually call `JS_FreeContext` to release it.
- Only returns a valid pointer under the QuickJS frontend; behavior is undefined under other frontends.

View File

@ -1,117 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/feature_framework_trace.md) \]
# Feature Trace API
Macro definitions for performance tracing (trace) instrumentation in the Feature framework. When enabled, these macros call the NuttX `sched_note` interface to record events; when disabled, they expand to no-ops.
Header file: `#include <feature_trace.h>`
## openvela Implementation Notes
- **Conditional compilation**: All trace macros are controlled by the `CONFIG_FEATURE_USE_SCHED_NOTE` configuration option.
- When enabled, they expand to `sched_note_*` series calls using the `NOTE_TAG_ALWAYS` tag.
- When disabled, they expand to no-ops (zero CPU/memory overhead), suitable for production builds.
- **Dependencies**: Depends on the NuttX kernel's `sched_note` mechanism; `CONFIG_SCHED_INSTRUMENTATION` related configurations must also be enabled.
- **Usage scenarios**: Instrument at Feature interface implementations or JS-Native boundaries. Combined with openvela trace analysis tools (such as SystemView, Perfetto), performance bottlenecks can be visualized.
- **Paired usage**: `FEATURE_NOTE_BEGIN*` / `FEATURE_NOTE_END*` must be called in pairs; otherwise trace event pairing will fail.
## Basic Instrumentation Macros
### FEATURE_NOTE_PRINTF
```c
FEATURE_NOTE_PRINTF(format, ...)
```
Instruments with a formatted string, similar to `printf`. Used to record custom debug information.
**Parameters**:
- `format` Format string.
- `...` Variable argument list corresponding to format placeholders.
### FEATURE_NOTE_BEGIN
```c
FEATURE_NOTE_BEGIN()
```
Marks the beginning of a code execution segment (no additional information). Must be paired with `FEATURE_NOTE_END`.
### FEATURE_NOTE_END
```c
FEATURE_NOTE_END()
```
Marks the end of a code execution segment. Pairs with the most recent `FEATURE_NOTE_BEGIN`.
## Tagged Instrumentation Macros
### FEATURE_NOTE_BEGIN_STR
```c
FEATURE_NOTE_BEGIN_STR(str)
```
Begin instrumentation with a string tag, used to identify the semantics of a code segment.
**Parameters**:
- `str` Event tag string. This string must remain valid for the entire duration of the trace event.
### FEATURE_NOTE_END_STR
```c
FEATURE_NOTE_END_STR(str)
```
End instrumentation with a string tag, matching the corresponding `FEATURE_NOTE_BEGIN_STR` tag.
**Parameters**:
- `str` Event tag string (must match the tag of the begin instrumentation).
### FEATURE_NOTE_MARK
```c
FEATURE_NOTE_MARK(str)
```
Places an instant marker point without requiring pairing. Used to mark a single event on the timeline.
**Parameters**:
- `str` Marker tag string.
## Scoped Instrumentation Macros
### FEATURE_NOTE_BEGIN_LOCAL / FEATURE_NOTE_END_LOCAL
```c
FEATURE_NOTE_BEGIN_LOCAL(str)
// traced code
FEATURE_NOTE_END_LOCAL()
```
Begin/end instrumentation with local variable scope. Internally saves the tag via a local variable, avoiding complex parameter passing from the caller.
**Parameters**:
- `str` Event tag string.
**Usage example**:
```c
void my_feature_func(void)
{
FEATURE_NOTE_BEGIN_LOCAL("my_feature_func");
// ... business logic ...
FEATURE_NOTE_END_LOCAL();
}
```
**Notes**:
- `FEATURE_NOTE_BEGIN_LOCAL` and `FEATURE_NOTE_END_LOCAL` must be used as a pair within the same scope. The macro is wrapped internally using a `do { ... } while(0)` pattern and relies on the compiler recognizing the scope.
- The macro internally introduces a local variable named `note_temp_str`. Do not use this variable name within the same scope.

View File

@ -1,366 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/feature_framework_types.md) \]
# Feature Types API
Basic data type definitions for the Feature framework, used by Feature developers.
Header: `#include <feature_types.h>`
## openvela Implementation Notes
- **Frontend-agnostic**: Wraps objects from various frontends (QuickJS, WAMR, etc.) into a unified `ft_value_t` type, so Feature developers do not need to be aware of specific frontend differences
- **Type system**: Provides a unified type identifier for parameter passing through the `FeaturePrimitiveType` enum; internally encodes type information and memory management flags via the `FT_SET_PRIMITIVE_TYPE(base, flags)` macro
- **Reference counting**: `TypeFlags` marks whether a type requires managed memory (`TYPE_FLAGS_POINTER` requires `malloc/free`, while `TYPE_FLAGS_VALUE` does not)
- **Error code ranges**: General error codes start from 200, custom error codes start from 400, and developers can extend them as needed
## Primitive Type Aliases
Provides `Ft`-prefixed aliases for basic C types, making it easier to identify type semantics in Feature interfaces.
```c
typedef int FtInt; // Equivalent to int32_t
typedef int8_t FtInt8;
typedef uint8_t FtUint8;
typedef int16_t FtInt16;
typedef uint16_t FtUint16;
typedef int32_t FtInt32;
typedef uint32_t FtUint32;
typedef int64_t FtInt64;
typedef uint64_t FtUint64;
typedef float FtFloat;
typedef double FtDouble;
typedef bool FtBool;
typedef const char* FtString; // Constant string
typedef ft_value_t* FtAny; // Generic ft_value_t reference
typedef int32_t FtCallbackId; // Callback ID
typedef int32_t FtEventId; // Event ID
typedef int32_t FtPromiseId; // Promise ID
```
## Handle Types
Opaque handles for core Feature framework objects. Developers can only operate on them through framework APIs and should not access the underlying structures directly.
```c
typedef void* FeatureRegistryHandle; // Feature registry handle
typedef void* FeatureManagerHandle; // Feature manager handle
typedef void* FeatureProtoHandle; // Feature prototype handle (one per quick app)
typedef void* FeatureInstanceHandle; // Feature instance handle (one per require)
typedef void* FeatureInterfaceHandle; // Feature interface handle
typedef void* FeatureRuntimeContext; // Frontend runtime context (e.g. QuickJS RuntimeContext)
typedef void* FeatureRawContextHandle; // Raw runtime context
typedef struct _FeatureWorker* FeatureWorkerHandle; // Worker handle
typedef uintptr_t FeatureType; // Feature type flag
```
## Callback Function Types
```c
// Generic native function pointer
typedef void (*NativeFunc)(void);
// Feature async task callback
typedef void (*FeatureTaskCallback)(int status, void* data);
// Feature async task callback (extended, with instance handle)
typedef void (*FeatureTaskCallbackExt)(int status, uint64_t data,
FeatureInstanceHandle feature);
// Event change listener callback
typedef void (*FeatureEventChangeListener)(FeatureInstanceHandle data,
FtEventId eid,
FeatureEventStatus status);
// Manager userdata release callback
typedef void (*ManagerUserdataFreeCallback)(void* data);
// Feature registration function
typedef bool (*FeatureRegistryFunc)(FeatureRegistryHandle);
```
## Enum Types
### FeatureTaskMode
Running mode for Feature asynchronous tasks.
```c
enum FeatureTaskMode {
FEATURE_TASK_MODE_FREE = 0, // Async task has ended
FEATURE_TASK_MODE_NORMAL = 1, // Async task running normally
};
```
### FeaturePromiseType
Promise type identifier. The Feature framework supports both traditional callback and Promise asynchronous models.
```c
typedef enum FeaturePromiseType {
FEATURE_PROMISE_TYPE_INVALID = -1, // Invalid type
FEATURE_PROMISE_TYPE_PROMISE = 0, // Promise model
FEATURE_PROMISE_TYPE_CALLBACKS = 1, // Callback model
} FeaturePromiseType;
```
### TypeFlags
Memory management flags for types, used to determine whether memory needs to be freed.
```c
enum TypeFlags {
TYPE_FLAGS_VALUE = 1, // Value type, no free needed
TYPE_FLAGS_POINTER, // Pointer type, requires malloc/free
TYPE_FLAGS_RAWPOINTER = TYPE_FLAGS_POINTER | 1, // Raw pointer, no free needed
TYPE_FLAGS_UNMANAGED_POINTER = TYPE_FLAGS_RAWPOINTER, // Unmanaged pointer
};
```
### FeaturePrimitiveType
Primitive type encoding used for parameter passing. The macro `FT_SET_PRIMITIVE_TYPE(base, flags)` combines the type base value with memory management flags.
```c
#define FT_SET_PRIMITIVE_TYPE(base, flags) ((base << 2) | (flags))
enum FeaturePrimitiveType {
FT_VOID = FT_SET_PRIMITIVE_TYPE(FT_VOID_BASE, TYPE_FLAGS_VALUE), // 1
FT_INT = FT_SET_PRIMITIVE_TYPE(FT_INT_BASE, TYPE_FLAGS_VALUE), // 5
FT_INT8 = FT_SET_PRIMITIVE_TYPE(FT_INT8_BASE, TYPE_FLAGS_VALUE), // 9
FT_UINT8 = FT_SET_PRIMITIVE_TYPE(FT_UINT8_BASE, TYPE_FLAGS_VALUE), // 13
FT_INT16 = FT_SET_PRIMITIVE_TYPE(FT_INT16_BASE, TYPE_FLAGS_VALUE), // 17
FT_UINT16 = FT_SET_PRIMITIVE_TYPE(FT_UINT16_BASE, TYPE_FLAGS_VALUE), // 21
FT_INT32 = FT_SET_PRIMITIVE_TYPE(FT_INT32_BASE, TYPE_FLAGS_VALUE), // 25
FT_UINT32 = FT_SET_PRIMITIVE_TYPE(FT_UINT32_BASE, TYPE_FLAGS_VALUE), // 29
FT_INT64 = FT_SET_PRIMITIVE_TYPE(FT_INT64_BASE, TYPE_FLAGS_VALUE), // 33
FT_UINT64 = FT_SET_PRIMITIVE_TYPE(FT_UINT64_BASE, TYPE_FLAGS_VALUE), // 37
FT_FLOAT = FT_SET_PRIMITIVE_TYPE(FT_FLOAT_BASE, TYPE_FLAGS_VALUE), // 41
FT_DOUBLE = FT_SET_PRIMITIVE_TYPE(FT_DOUBLE_BASE, TYPE_FLAGS_VALUE), // 45
FT_BOOLEAN = FT_SET_PRIMITIVE_TYPE(FT_BOOLEAN_BASE, TYPE_FLAGS_VALUE), // 49
FT_STRING = FT_SET_PRIMITIVE_TYPE(FT_STRING_BASE, TYPE_FLAGS_POINTER), // 54
FT_CHAR = FT_STRING, // 54, equivalent to FT_STRING
FT_ANY_REF = FT_SET_PRIMITIVE_TYPE(FT_ANY_REF_BASE, TYPE_FLAGS_POINTER), // 58
FT_JSON_OBJ = FT_SET_PRIMITIVE_TYPE(FT_JSON_OBJ_BASE, TYPE_FLAGS_POINTER), // 62
};
```
### FeatureErrorCode
Error code definitions for the Feature framework.
```c
typedef enum FeatureErrorCode {
FT_ERR_GENERAL = 200, // General error
FT_ERR_ARGS = 202, // Argument error
FT_ERR_TIMEOUT = 204, // Timeout
FT_ERR_IOERROR = 300, // IO error
FT_ERR_PATH_NOT_EXISTS = 301, // Path does not exist
FT_ERR_CUSTOM_BEGIN = 400, // Custom error code start
FT_ERR_TASK_FAILED = 1000, // Task failed
FT_ERR_TASK_NOT_EXISTS = 1001, // Task does not exist
FT_ERR_CANCEL_ERROR_CODE = 1002, // Cancellation error
} FeatureErrorCode;
```
### FeatureEventStatus
Event change status, used to notify listeners when events are added or removed.
```c
typedef enum FeatureEventStatus {
FEATURE_EVENT_ADDED, // Event added
FEATURE_EVENT_REMOVED, // Event removed
} FeatureEventStatus;
```
### FeaturePermsRejectReason
Permission rejection reason.
```c
typedef enum FeaturePermsRejectReason {
FEATURE_PERMS_DENIED = 400, // Permission denied
FEATURE_PERMS_ERROR, // Permission error
FEATURE_PERMS_NO_BG, // Background not allowed
} FeaturePermsRejectReason;
```
### FeatureWorkerCancelResult
Worker cancellation result.
```c
enum FeatureWorkerCancelResult {
FeatureWorkerCancelSuccess, // Successfully cancelled
FeatureWorkerCancelPending, // Task is pending, cannot cancel
FeatureWorkerCancelInvalid, // Worker is invalid
FeatureWorkerCancelUnknownError, // Unknown error
};
```
### FeatureWorkerState
Worker running state.
```c
enum FeatureWorkerState {
FEATURE_WORKER_PENDING, // Pending
FEATURE_WORKER_RUNNING, // Running
FEATURE_WORKER_INVALID, // Invalid state
FEATURE_WORKER_RESOLVED, // Resolved
FEATURE_WORKER_REJECTED, // Rejected
FEATURE_WORKER_FINISHED, // Finished
};
```
### FeatureManagerType
Feature manager type.
```c
typedef enum FeatureManagerType {
FEATURE_MANAGER_JS, // JS type Feature manager
FEATURE_MANAGER_WAMR, // WAMR type Feature manager
} FeatureManagerType;
```
## Structures
### FtArray
Generic dynamic array structure for the Feature framework.
```c
typedef struct FtArray {
int32_t _size; // Current number of elements
int32_t _capacity; // Current capacity
void* _element; // Element pointer
} FtArray;
```
### FtJsonObject
JSON object handle, internally a flexible string.
```c
typedef struct _FtJsonObject {
char str[0]; // Internal string data
} *FtJsonObject;
```
### AppendData
Generic union for appending elements to an array, supporting multiple primitive types.
```c
typedef union AppendData {
int32_t i32; // 32-bit signed integer
int64_t i64; // 64-bit signed integer
uint32_t u32; // 32-bit unsigned integer
uint64_t u64; // 64-bit unsigned integer
float f32; // Single-precision float
double f64; // Double-precision float
void* ptr; // Arbitrary pointer
const char* str; // String
} AppendData;
```
### FtVariParams
Variable-length parameter pack.
```c
typedef struct FtVariParams {
int32_t vari_count; // Parameter count
ft_value_t* vari_args; // Parameter array pointer
} FtVariParams;
```
### FeatureWorkerResult
Union for Worker execution results.
```c
typedef union _FeatureWorkerResult {
int64_t ival; // Signed integer result
uint64_t uval; // Unsigned integer result
double dval; // Floating-point result
char* str; // String result
void* ptr; // Pointer result
} FeatureWorkerResult;
```
### VTable
Virtual function table used when creating Feature interfaces.
```c
typedef struct VTable {
int size; // Number of members
NativeFunc finalizer; // Destructor function
const NativeFunc* members; // Member function array
} VTable;
```
### FeatureManagerCreateInfo
Configuration information required when creating a Feature manager.
```c
typedef struct FeatureManagerCreateInfo {
FeatureRawContextHandle raw_ctx; // Raw context handle
ReleaseRawContextCb release_cb; // Raw context release callback
FeatureManagerType manager_type; // Manager type (JS / WAMR)
const char* package_name; // Quick app package name
} FeatureManagerCreateInfo;
```
### FeatureMemoryDump
Memory diagnostic callback structure, used to collect memory usage statistics during debugging.
```c
typedef struct {
MemoryDumpCountCB count; // Single item memory count callback
MemoryDumpCountMetaCB count_meta; // Metadata count callback with name
MemoryDumpSubCB sub; // Recursive sub-item callback
} FeatureMemoryDump;
```
### ArgsErrorInfo
Argument error information. When a Feature call has mismatched parameter types, this information is passed through the `ArgsErrorCb` callback.
```c
typedef struct {
int argc; // Argument count
void* argv; // Argument list pointer
int error_code; // Error code
const char* error_msg; // Error message
} ArgsErrorInfo;
```
### FeaturePermissionsInfo
Permission check information.
```c
typedef struct FeaturePermissionsInfo {
const FeaturePermissions* permissions; // Permission descriptor
const char* api_name; // API name
bool has_async_cbs; // Whether it has async callbacks
} FeaturePermissionsInfo;
```
### FeatureRegistryTable
Feature registry table, used for batch registration of multiple Features.
```c
typedef struct _FeatureRegistryTable {
size_t count; // Number of entries
FeatureRegistryFunc data[]; // Registration function array (flexible member)
} FeatureRegistryTable, *FeatureRegistryTableHandle;
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -1,27 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/feature/index.md) \]
# Feature Framework API
The Feature framework is the Native extension development framework for openvela QuickApp, providing interoperability between JS and C/C++. Developers can extend new system capabilities for QuickApps through the Feature framework, which handles parameter conversion, lifecycle management, asynchronous programming models, and automatic interface generation (JIDL).
## Framework Overview
- **[Feature Framework Overview](feature_framework.md)** — Architecture, concept model (Module / Prototype / Instance), JIDL interface description language
## Core Data Types
- **[Type Definitions](feature_framework_types.md)** — Basic type aliases, handle types, enumerations, structures
## Runtime Interfaces
- **[Context and Data Conversion](feature_framework_context.md)** — `ft_value_t` creation/destruction, type conversion, array/object operations
- **[Feature Export Interface](feature_framework_export.md)** — Full runtime API for Feature developers (memory, callbacks, Promise, events, Worker, JSON)
- **[Framework Management Interface](feature_framework_main_export.md)** — APIs for QuickApp framework implementors to create and configure the Feature manager
## Frontend Interoperability
- **[QuickJS Interoperability](feature_framework_qjs_export.md)** — `ft_value_t` and `JSValue` conversion (QuickJS frontend only)
## Debugging and Performance
- **[Trace Instrumentation](feature_framework_trace.md)** — Built-in sched_note performance tracing macros for the Feature framework

View File

@ -1,19 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/framework/index.md) \]
# Application Framework
The openvela application framework provides unified system capability interfaces for upper-layer applications, covering core subsystems such as inter-process communication, Bluetooth and connectivity management, multimedia, telephony services, graphical user interfaces, and trusted execution environments. Developers can use these APIs to quickly build IoT and smart device applications without worrying about underlying hardware differences.
The framework is organized into the following modules by functional domain:
- **Binder** — Inter-Process Communication (IPC) framework development guide (API is consistent with Android NDK Binder, see [Android Binder NDK Documentation](https://developer.android.com/ndk/reference/group/ndk-binder))
- **[Bluetooth](bluetooth/index.md)** — Bluetooth protocol stack interfaces, supporting BLE, Classic Bluetooth, and various profiles (A2DP, HFP, HID, etc.)
- **[Telephony](telephony/index.md)** — Cellular network communication interfaces, covering voice calls, SMS, data connections, SIM card management, etc.
- **[Media](media/index.md)** — Audio/video playback and recording framework
- **[Services](services/index.md)** — Core system services including Activity Manager Service (AMS) and Package Manager Service (PMS)
- **[Feature](feature/index.md)** — SystemCapability query interfaces
- **[QuickApp](quickapp/index.md)** — Lightweight application runtime framework
- **[Utils](utils/index.md)** — Common utilities including Log and Trace
- **[KVDB](kvdb.md)** — Lightweight key-value persistent storage
- **[Security](security.md)** — Trusted Execution Environment (TEE) interfaces based on OP-TEE
- **[uORB](uorb.md)** — Publish/subscribe message bus for asynchronous inter-module data communication

View File

@ -1,540 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/framework/kvdb.md) \]
# KVDB API
KVDB provides lightweight key-value persistent storage, built on the UnQLite embedded database, with an API design inspired by the Android properties specification.
Headers: `#include <kvdb.h>`, `#include <cutils/properties.h>`
## openvela Implementation Notes
- **Storage Backend**: Built on the UnQLite embedded database
- **Value Types**: Supports string, boolean, int32, int64, and binary data
- **Sync/Async Writes**: `property_set()` performs synchronous writes; `property_set_oneway()` performs asynchronous writes (does not wait for persistence to complete)
- **Monitoring**: Supports key-value change monitoring via `property_wait()` or `property_monitor_*` interfaces
- **CLI Tools**: Provides `setprop`/`getprop` command-line tools for debugging
## Read Interfaces
### property_get
```c
int property_get(const char *key, char *value, const char *default_value);
```
Retrieves a string property value. Returns the default value if the key does not exist.
**Parameters**:
- `key` Property key name.
- `value` Buffer to store the property value.
- `default_value` Default value when the key does not exist; may be `NULL`.
**Returns**:
Returns the length of the property value.
### property_get_bool
```c
int8_t property_get_bool(const char *key, int8_t default_value);
```
Retrieves a boolean property value.
**Parameters**:
- `key` Property key name.
- `default_value` Default value when the key does not exist.
**Returns**:
Returns the boolean value of the property.
### property_get_int32
```c
int32_t property_get_int32(const char *key, int32_t default_value);
```
Retrieves a 32-bit integer property value.
**Parameters**:
- `key` Property key name.
- `default_value` Default value when the key does not exist.
**Returns**:
Returns the int32 value of the property.
### property_get_int64
```c
int64_t property_get_int64(const char *key, int64_t default_value);
```
Retrieves a 64-bit integer property value.
**Parameters**:
- `key` Property key name.
- `default_value` Default value when the key does not exist.
**Returns**:
Returns the int64 value of the property.
### property_get_buffer
```c
ssize_t property_get_buffer(const char *key, void *value, size_t size);
```
Retrieves a binary buffer property value.
**Parameters**:
- `key` Property key name.
- `value` Buffer to store the data.
- `size` Buffer size.
**Returns**:
Returns the number of bytes read on success, or a negative error code on failure.
### property_get_binary
```c
ssize_t property_get_binary(const char *key, void *value, size_t val_len);
```
Retrieves a binary property value.
**Parameters**:
- `key` Property key name.
- `value` Buffer to store the data.
- `val_len` Buffer size.
**Returns**:
Returns the number of bytes read on success, or a negative error code on failure.
### property_get_with_err
```c
int property_get_with_err(const char *key, char *value);
```
Retrieves a string property value, distinguishing between "key does not exist" and "value is empty" via the return value.
**Parameters**:
- `key` Property key name.
- `value` Buffer to store the property value.
**Returns**:
Returns the property value length on success, or a negative error code when the key does not exist.
### property_get_bool_with_err
```c
int property_get_bool_with_err(const char *key, int8_t *value);
```
Reads a boolean value with error detection.
**Parameters**:
- `key` Property key name.
- `value` Pointer to store the boolean result.
**Returns**:
Returns `0` on success, or a negative error code when the key does not exist or the type does not match.
### property_get_int32_with_err
```c
int property_get_int32_with_err(const char *key, int32_t *value);
```
Reads a 32-bit signed integer with error detection.
**Parameters**:
- `key` Property key name.
- `value` Pointer to store the int32 result.
**Returns**:
Returns `0` on success, or a negative error code when the key does not exist or the type does not match.
### property_get_int64_with_err
```c
int property_get_int64_with_err(const char *key, int64_t *value);
```
Reads a 64-bit signed integer with error detection.
**Parameters**:
- `key` Property key name.
- `value` Pointer to store the int64 result.
**Returns**:
Returns `0` on success, or a negative error code when the key does not exist or the type does not match.
## Write Interfaces
### property_set
```c
int property_set(const char *key, const char *value);
```
Sets a string property value (synchronous write; waits for persistence to complete).
**Parameters**:
- `key` Property key name.
- `value` Property value.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### property_set_oneway
```c
int property_set_oneway(const char *key, const char *value);
```
Sets a string property value (asynchronous write; does not wait for persistence to complete). Offers better performance but does not guarantee immediate persistence.
**Parameters**:
- `key` Property key name.
- `value` Property value.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### property_set_bool
```c
int property_set_bool(const char *key, int8_t value);
```
Sets a boolean property value (synchronous write).
**Parameters**:
- `key` Property key name.
- `value` Boolean value (`0` or non-`0`).
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_int32
```c
int property_set_int32(const char *key, int32_t value);
```
Sets a 32-bit signed integer property value (synchronous write).
**Parameters**:
- `key` Property key name.
- `value` int32 value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_int64
```c
int property_set_int64(const char *key, int64_t value);
```
Sets a 64-bit signed integer property value (synchronous write).
**Parameters**:
- `key` Property key name.
- `value` int64 value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_bool_oneway
```c
int property_set_bool_oneway(const char *key, int8_t value);
```
Asynchronously sets a boolean property value (does not wait for persistence to complete).
**Parameters**:
- `key` Property key name.
- `value` Boolean value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_int32_oneway
```c
int property_set_int32_oneway(const char *key, int32_t value);
```
Asynchronously sets an int32 property value (does not wait for persistence to complete).
**Parameters**:
- `key` Property key name.
- `value` int32 value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_int64_oneway
```c
int property_set_int64_oneway(const char *key, int64_t value);
```
Asynchronously sets an int64 property value (does not wait for persistence to complete).
**Parameters**:
- `key` Property key name.
- `value` int64 value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_buffer
```c
int property_set_buffer(const char *key, const void *value, size_t size);
```
Sets a binary buffer property value (synchronous write).
**Parameters**:
- `key` Property key name.
- `value` Pointer to the data buffer.
- `size` Buffer size in bytes.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_buffer_oneway
```c
int property_set_buffer_oneway(const char *key, const void *value, size_t size);
```
Asynchronously sets a binary buffer property value (does not wait for persistence to complete).
**Parameters**:
- `key` Property key name.
- `value` Pointer to the data buffer.
- `size` Buffer size in bytes.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### property_set_binary
```c
int property_set_binary(const char *key, const void *value, size_t val_len, bool oneway);
```
Sets a binary property value.
**Parameters**:
- `key` Property key name.
- `value` Binary data.
- `val_len` Data length.
- `oneway` Whether to write asynchronously.
### property_delete
```c
int property_delete(const char *key);
```
Deletes the property with the specified key.
**Parameters**:
- `key` Property key name to delete.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Management Interfaces
### property_commit
```c
int property_commit(void);
```
Forces all pending property writes to be persisted to storage.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### property_load
```c
int property_load(const char *path);
```
Loads properties from a file into the database.
**Parameters**:
- `path` Path to the property file.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### property_exit
```c
int property_exit(void);
```
Closes KVDB and releases resources.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### property_list
```c
int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);
```
Iterates over all properties, invoking the callback function for each one.
**Parameters**:
- `propfn` Callback function that receives the key, value, and user data.
- `cookie` User data passed to the callback function.
### property_list_binary
```c
int property_list_binary(void (*propfn)(const char *key, const void *value, size_t val_len, void *cookie), void *cookie);
```
Iterates over all binary properties, invoking the callback function for each one. Unlike `property_list`, the callback includes a `val_len` parameter, making it suitable for non-string values.
**Parameters**:
- `propfn` Callback function with signature `void (*)(const char *key, const void *value, size_t val_len, void *cookie)`, receiving the key, binary value, value length, and user data.
- `cookie` User data passed to the callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Monitoring Interfaces
### property_wait
```c
ssize_t property_wait(const char *key, char *newkey, void *newvalue, size_t val_len, int timeout);
```
Waits for a property change notification. Blocks until the specified key (or any key) changes or the timeout expires.
**Parameters**:
- `key` Key name to monitor; `NULL` to monitor all keys.
- `newkey` Buffer to store the changed key name.
- `newvalue` Buffer to store the new value.
- `val_len` Value buffer size.
- `timeout` Timeout in milliseconds; -1 for infinite wait.
**Returns**:
Returns the value length on success, 0 on timeout, or a negative error code on failure.
### property_monitor_open
```c
int property_monitor_open(const char *key);
```
Opens a property monitoring file descriptor, which can be used with `poll()`.
**Parameters**:
- `key` Key name to monitor; `NULL` to monitor all keys.
**Returns**:
Returns a file descriptor on success, or a negative error code on failure.
### property_monitor_read
```c
ssize_t property_monitor_read(int fd, char *newkey, void *newvalue, size_t val_len);
```
Reads a change event from the monitoring file descriptor.
**Parameters**:
- `fd` File descriptor returned by `property_monitor_open()`.
- `newkey` Buffer to store the changed key name.
- `newvalue` Buffer to store the new value.
- `val_len` Value buffer size.
**Returns**:
Returns the value length on success, or a negative error code on failure.
### property_monitor_close
```c
int property_monitor_close(int fd);
```
Closes a property monitoring file descriptor.
**Parameters**:
- `fd` File descriptor to close.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,49 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/index.md) \]
# Multimedia API
The openvela multimedia framework provides unified capabilities for audio/video playback, recording, audio focus management, policy control, and media session, along with voice wakeup and utility interfaces.
## openvela Implementation Notes
- **Codec Backend**: The underlying audio/video codec, muxing/demuxing, and filter capabilities are provided by **FFmpeg**, with source located at `external/ffmpeg/` (LGPL v2.1+)
- **Usage Recommendations**:
- Prefer the openvela `framework/media` wrappers (`media_player_*` / `media_recorder_*`, etc.), which integrate audio focus, policy control, and session synchronization
- For custom filter graphs, direct codec access, or probing non-standard streaming media, use the FFmpeg native API directly; refer to the [FFmpeg Official Documentation](https://ffmpeg.org/documentation.html)
- **FFmpeg Integration Configuration** (`external/ffmpeg/Kconfig`):
```kconfig
CONFIG_LIB_FFMPEG=y # Main switch: enable FFmpeg library
CONFIG_LIB_FFMPEG_CONFIGURATION="" # Arguments passed to FFmpeg ./configure for component trimming
CONFIG_LIB_FFMPEG_TEST=n # Whether to compile FFmpeg test targets
CONFIG_UTILS_FFMPEG_PRIORITY=100 # Task priority for the ffmpeg CLI tool
CONFIG_UTILS_FFMPEG_STACKSIZE=51200 # Task stack size for the ffmpeg CLI tool
```
Component trimming is done via the `CONFIG_LIB_FFMPEG_CONFIGURATION` string passed to FFmpeg's built-in `./configure` script. For example:
```kconfig
CONFIG_LIB_FFMPEG_CONFIGURATION="--disable-everything --enable-decoder=mp3,aac --enable-demuxer=mov,mp4"
```
For available `--enable-*` / `--disable-*` options, refer to FFmpeg's official `./configure --help`.
## Core Capabilities
- **[Player](media_player.md)** — Audio/video playback (local/network stream/byte stream)
- **[Recorder](media_recorder.md)** — Audio/video recording and image capture
- **[Media Session](media_session.md)** — Controller-controllee playback control and state synchronization
## Audio Policy
- **[Audio Focus](media_focus.md)** — Multi-application audio playback priority coordination
- **[Audio Policy](media_policy.md)** — Audio routing, device management, volume and mode switching
## Voice Wakeup
- **[Media Trigger](media_trigger.md)** — High-level voice wakeup interface (acoustic model loading + recognition control)
- **[Sound Model](media_trigger_model.md)** — Low-level acoustic model operations (loading/properties/hotword detection)
## Utilities and Debugging
- **[Media Utils](media_utils.md)** — DTMF signal generation, event name lookup, dump, custom commands

View File

@ -1,237 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_focus.md) \]
# Audio Focus Management API
Audio Focus is used to coordinate playback priority among multiple audio applications. When multiple applications request audio focus simultaneously, the system determines which should play, stop, or lower volume based on the scenario, and notifies each application via callbacks.
Header: `#include <media_focus.h>`
## openvela Implementation Notes
- **Scenario priority**: The request type is identified by a `scenario` string (e.g. `MEDIA_SCENARIO_MUSIC`, `MEDIA_SCENARIO_NOTIFICATION`). The framework returns a focus suggestion based on scenario priority.
- **Synchronous / Asynchronous dual model**: Two sets of interfaces are provided:
- Synchronous: `media_focus_*` series, suitable for simple scenarios.
- Asynchronous (libuv-based): `media_uv_focus_*` series, requires `CONFIG_LIBUV`, suitable for applications based on uv_loop.
- **Auto-reply**: The `request2` interface adds an `auto_reply` parameter. When set to `1`, the framework automatically replies to received suggestions without the application manually calling `reply`.
- **Callback disconnection protection**: Even if `initial_suggestion` returns `MEDIA_FOCUS_STOP` (meaning the focus is immediately preempted by another holder), the framework still returns a valid handle. You must call `abandon` to release it; otherwise a resource leak will occur.
- **Legacy vs. new interfaces**: `media_focus_request` / `media_uv_focus_request` are marked deprecated. Use the versions with the `2` suffix instead.
## Focus Request (Synchronous)
### media_focus_request
```c
void* media_focus_request(int* initial_suggestion, const char* scenario,
media_focus_callback on_suggestion, void* cookie)
__attribute__((deprecated));
```
Request audio focus (**deprecated**, use `media_focus_request2` instead).
**Parameters**:
- `initial_suggestion` Output parameter that returns the initial focus suggestion, valued as a `MEDIA_FOCUS_*` constant.
- `scenario` Scenario identifier string, valued as a `MEDIA_SCENARIO_*` constant.
- `on_suggestion` Callback function invoked when the focus suggestion changes.
- `cookie` User data passed to the callback.
**Returns**:
Returns a focus handle on success, or `NULL` on failure.
**Notes**:
- If `initial_suggestion` is `MEDIA_FOCUS_STOP`, `on_suggestion` will not be called, but a valid handle is still returned. The caller must call `media_focus_abandon` to release it; otherwise a leak will occur.
### media_focus_request2
```c
void* media_focus_request2(int* initial_suggestion, const char* scenario,
media_focus_callback2 on_suggestion,
int auto_reply, void* cookie);
```
Request audio focus (recommended, replaces `media_focus_request`).
**Parameters**:
- `initial_suggestion` Output parameter that returns the initial focus suggestion, valued as a `MEDIA_FOCUS_*` constant.
- `scenario` Scenario identifier string, valued as a `MEDIA_SCENARIO_*` constant.
- `on_suggestion` Callback function invoked when the focus suggestion changes (new signature includes `req_id`).
- `auto_reply` Whether to enable auto-reply: `1` means the framework automatically replies to focus suggestions, `0` means the application manually calls `media_focus_reply`.
- `cookie` User data passed to the callback.
**Returns**:
Returns a focus handle on success, or `NULL` on failure.
**Notes**:
- If `initial_suggestion` is `MEDIA_FOCUS_STOP`, `on_suggestion` will not be called, but a valid handle is still returned. The caller must call `media_focus_abandon` to release it.
**Example**:
```c
int initial_suggestion;
context->handle = media_focus_request2(&initial_suggestion,
MEDIA_SCENARIO_MUSIC, demo_focus_callback, 1, context);
if (!context->handle) {
// handle error
}
if (initial_suggestion == MEDIA_FOCUS_STOP)
media_focus_abandon(context->handle);
```
### media_focus_abandon
```c
int media_focus_abandon(void* handle);
```
Release audio focus.
**Parameters**:
- `handle` The focus handle to release.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### media_focus_reply
```c
int media_focus_reply(void* handle, int req_id);
```
Reply to a focus request. Used when `request2` has `auto_reply` set to `0`, to manually acknowledge the focus suggestion.
**Parameters**:
- `handle` The focus handle.
- `req_id` Request ID, passed in by the focus suggestion callback.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Focus Request (Asynchronous, libuv-based)
The following interfaces are only available when `CONFIG_LIBUV` is enabled.
### media_uv_focus_request
```c
void* media_uv_focus_request(void* loop, const char* scenario,
media_focus_callback on_suggestion, void* cookie)
__attribute__((deprecated));
```
Asynchronously request audio focus (**deprecated**, use `media_uv_focus_request2` instead).
**Parameters**:
- `loop` The `uv_loop_t*` event loop of the current thread.
- `scenario` Scenario identifier string, valued as a `MEDIA_SCENARIO_*` constant.
- `on_suggestion` Callback function invoked when the focus suggestion changes.
- `cookie` User data passed to the callback.
**Returns**:
Returns an asynchronous focus handle on success, or `NULL` on failure.
**Notes**:
- When the `on_suggestion` callback receives `MEDIA_FOCUS_STOP`, the application should call `media_uv_focus_abandon` to release the handle.
### media_uv_focus_request2
```c
void* media_uv_focus_request2(void* loop, const char* scenario,
media_focus_callback2 on_suggestion,
int auto_reply, void* cookie);
```
Asynchronously request audio focus (recommended, replaces `media_uv_focus_request`).
**Parameters**:
- `loop` The `uv_loop_t*` event loop of the current thread.
- `scenario` Scenario identifier string, valued as a `MEDIA_SCENARIO_*` constant.
- `on_suggestion` Callback function invoked when the focus suggestion changes (new signature includes `req_id`).
- `auto_reply` Whether to enable auto-reply: `1` means the framework automatically replies to focus suggestions.
- `cookie` User data passed to the callback.
**Returns**:
Returns an asynchronous focus handle on success, or `NULL` on failure.
**Example**:
```c
void user_on_suggestion(int suggestion, int req_id, void* cookie) {
UserContext* ctx = cookie;
switch (suggestion) {
case MEDIA_FOCUS_STOP:
media_uv_focus_abandon(ctx->handle, NULL);
break;
}
}
ctx->handle = media_uv_focus_request2(loop, MEDIA_SCENARIO_MUSIC,
user_on_suggestion, 1, ctx);
```
### media_uv_focus_abandon
```c
int media_uv_focus_abandon(void* handle, media_uv_callback on_abandon);
```
Asynchronously release audio focus.
**Parameters**:
- `handle` The asynchronous focus handle.
- `on_abandon` Callback invoked after the release is complete, typically used to free the cookie.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_focus_reply
```c
int media_uv_focus_reply(void* handle, int req_id);
```
Asynchronously reply to a focus request. Used when `request2` has `auto_reply` set to `0`.
**Parameters**:
- `handle` The asynchronous focus handle.
- `req_id` Request ID.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Debug Interface
### media_focus_dump
```c
void media_focus_dump(const char* options);
```
Dump focus stack information for debugging.
**Parameters**:
- `options` Dump options (currently unused).
**Notes**:
- This interface will be merged into the unified `media_dump()` in the future.

View File

@ -1,833 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_player.md) \]
# Multimedia Player API
Audio and video playback supporting local files and network streaming.
Header: `#include <media_player.h>`
## openvela Implementation Notes
- **Synchronous/Asynchronous dual model**: Two parallel sets of interfaces are provided
- Synchronous: `media_player_*` series, calls return in the current thread
- Asynchronous: `media_uv_player_*` series, based on libuv event loop, requires `CONFIG_LIBUV`
- **Lifecycle**: `open` creates the player → `prepare` sets the source → `start` begins playback → `stop`/`close` releases resources
- **Data sources**: Two input methods are supported
- Local/network URL: Specify directly via `prepare(url)`
- Byte stream buffer: Push via `write_data`, or obtain the underlying socket via `get_socket`
- **Event callback**: Register an event listener via `set_event_callback` to receive playback state changes, errors, and other notifications
- **Parameter configuration**: Common parameters are read/written via `set_property` / `get_property` (e.g., sample rate, channel count)
## Synchronous Interface - Lifecycle
### media_player_open
```c
void* media_player_open(const char* stream);
```
Opens a player for the specified stream type.
**Parameters**:
- `stream` Stream type constant. Different stream types have different routing logic.
**Returns**:
Returns the player handle on success, or `NULL` on failure.
### media_player_close
```c
int media_player_close(void* handle, int pending_stop);
```
Closes the player.
**Parameters**:
- `handle` Player handle.
- `pending_stop` Whether to wait for stop to complete before closing: 0 means stop immediately and close, 1 means wait for the current track to finish before closing. This parameter is only effective for audio players; setting it to 1 for video players has no waiting effect.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_player_set_event_callback
```c
int media_player_set_event_callback(void* handle, void* event_cookie, media_event_callback on_event);
```
Sets the event callback to monitor stream state changes.
**Parameters**:
- `handle` Player handle.
- `event_cookie` Callback context parameter.
- `on_event` Event callback function for receiving stream state change notifications.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_prepare
```c
int media_player_prepare(void* handle, const char* url, const char* options);
```
Prepares the playback resource.
**Parameters**:
- `handle` Player handle.
- `url` Resource path, supporting two modes: 1. URL mode: `url` is a local file path or network address, the framework reads and plays it; 2. BUFFER mode: `url` is `NULL`, the caller must continuously push data via `media_player_write_data()` or `media_player_get_socket()` + `write()`.
- `options` Additional configuration parameters for the resource, typically key-value pairs describing the resource format (e.g., `"format=s16le,sample_rate=44100,channels=2"`).
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_reset
```c
int media_player_reset(void* handle);
```
Resets the player.
**Parameters**:
- `handle` Player handle returned by `media_player_open`.
**Returns**:
Returns 0 on success, or a negated error code on failure.
## Synchronous Interface - Data Stream
### media_player_write_data
```c
ssize_t media_player_write_data(void* handle, const void* data, size_t len);
```
Writes data to the player for playback.
**Parameters**:
- `handle` Player handle.
- `data` Buffer address.
- `len` Buffer length to write.
**Returns**:
Returns the number of bytes sent on success, or a negated error code on failure.
### media_player_get_sockaddr
```c
int media_player_get_sockaddr(void* handle, struct sockaddr_storage* addr);
```
Gets the socket address information for buffer mode.
**Parameters**:
- `handle` Player handle.
- `addr` Socket address information.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_player_get_socket
```c
int media_player_get_socket(void* handle);
```
Gets the socket file descriptor for writing.
**Parameters**:
- `handle` Player handle.
**Returns**:
Returns the socket file descriptor on success, or a negated error code on failure.
### media_player_close_socket
```c
void media_player_close_socket(void* handle);
```
Closes the socket file descriptor.
**Parameters**:
- `handle` Player handle.
## Synchronous Interface - Playback Control
### media_player_start
```c
int media_player_start(void* handle);
```
Starts or resumes playback of the audio source.
**Parameters**:
- `handle` Player handle.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_stop
```c
int media_player_stop(void* handle);
```
Stops playback and clears the audio source.
**Parameters**:
- `handle` Player handle.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_pause
```c
int media_player_pause(void* handle);
```
Pauses playback.
**Parameters**:
- `handle` Player handle.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_seek
```c
int media_player_seek(void* handle, unsigned int position);
```
Seeks to the specified position from the beginning.
**Parameters**:
- `handle` Player handle.
- `position` Position in milliseconds.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_set_looping
```c
int media_player_set_looping(void* handle, int loop);
```
Sets the loop count.
**Parameters**:
- `handle` Player handle.
- `loop` Loop count; `-1` means infinite looping.
**Returns**:
Returns `0` on success, or a negated errno on failure.
## Synchronous Interface - State Query
### media_player_is_playing
```c
int media_player_is_playing(void* handle);
```
Checks the current playing status.
**Parameters**:
- `handle` Player handle.
**Returns**:
Returns a positive value if playing, zero if inactive, or a negative value on error.
### media_player_get_position
```c
int media_player_get_position(void* handle, unsigned int* position);
```
Gets the current playback position of the audio source.
**Parameters**:
- `handle` Player handle.
- `position` Output position in milliseconds.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_player_get_duration
```c
int media_player_get_duration(void* handle, unsigned int* duration);
```
Gets the total duration of the current audio source.
**Parameters**:
- `handle` Player handle.
- `duration` Output duration in milliseconds.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_player_get_latency
```c
int media_player_get_latency(void* handle, unsigned int* latency);
```
Gets the latency of the current audio source.
**Parameters**:
- `handle` Player handle.
- `latency` Output latency in frames.
**Returns**:
Returns `0` on success, or a negated errno on failure.
## Synchronous Interface - Volume and Properties
### media_player_set_volume
```c
int media_player_set_volume(void* handle, float volume);
```
Sets the volume.
**Parameters**:
- `handle` Player handle.
- `volume` Volume value in the range `[0.0, 1.0]`.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_player_get_volume
```c
int media_player_get_volume(void* handle, float* volume);
```
Gets the volume.
**Parameters**:
- `handle` Player handle.
- `volume` Output volume value in the range `[0.0, 1.0]`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_player_set_property
```c
int media_player_set_property(void* handle, const char* target, const char* key, const char* value);
```
Sets a property on the player.
**Parameters**:
- `handle` Player handle.
- `target` Target filter name.
- `key` Property key.
- `value` Property value.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_player_get_property
```c
int media_player_get_property(void* handle, const char* target, const char* key, char* value, int value_len);
```
Gets a property from the player.
**Parameters**:
- `handle` Player handle.
- `target` Target filter name.
- `key` Property key.
- `value` Output buffer.
- `value_len` Length of the output buffer.
**Returns**:
Returns `0` on success, or a negated errno on failure.
## Asynchronous Interface (libuv-based)
The following interfaces are only available when `CONFIG_LIBUV` is enabled. Callbacks execute on the `uv_loop`, avoiding blocking the calling thread.
### media_uv_player_open
```c
void* media_uv_player_open(void* loop, const char* stream, media_uv_callback on_open, void* cookie);
```
Opens an asynchronous player with the given stream type.
**Parameters**:
- `loop` The `uv_loop_t*` event loop handle for the current thread.
- `stream` Stream type constant. Different stream types have different routing logic.
- `on_open` Callback function triggered when the open operation completes.
- `cookie` Callback context shared by `on_open`, `on_event`, `on_connection`, and `on_close`.
**Returns**:
Returns the player handle on success, or `NULL` on failure.
### media_uv_player_listen
```c
int media_uv_player_listen(void* handle, media_event_callback on_event);
```
Listens to status change events by setting a callback.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_event` Event callback function invoked upon notification.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_close
```c
int media_uv_player_close(void* handle, int pending, media_uv_callback on_close);
```
Closes the asynchronous player.
**Parameters**:
- `handle` Asynchronous player handle.
- `pending` Whether to close in pending mode.
- `on_close` Callback function triggered when resource release completes.
**Returns**:
Returns 0 on success, or a negated error code for an invalid handle.
### media_uv_player_prepare
```c
int media_uv_player_prepare(void* handle, const char* url, const char* options, media_uv_object_callback on_connection, media_uv_callback on_prepare, void* cookie);
```
Prepares the audio source for playback.
**Parameters**:
- `handle` Asynchronous player handle.
- `url` Resource path, supporting two modes: 1. URL mode: `url` is a local file path or network address, the framework reads and plays it; 2. BUFFER mode: `url` is `NULL`, the caller must continuously push data via `media_player_write_data()` or `media_player_get_socket()` + `write()`.
- `options` Additional configuration parameters for the resource, typically key-value pairs describing the resource format (e.g., `"format=s16le,sample_rate=44100,channels=2"`).
- `on_connection` Callback function that receives the `uv_pipe_t` in BUFFER mode.
- `on_prepare` Result callback function.
- `cookie` Callback context for `on_prepare`.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_uv_player_reset
```c
int media_uv_player_reset(void* handle, media_uv_callback on_reset, void* cookie);
```
Resets the player.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_reset` Result callback function.
- `cookie` Callback context for `on_reset`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_start_auto
```c
int media_uv_player_start_auto(void* handle, const char* scenario, media_uv_callback on_start, void* cookie);
```
Plays or resumes the prepared audio source with automatic focus request.
**Parameters**:
- `handle` Asynchronous player handle.
- `scenario` Scenario constant; different scenarios correspond to different focus priorities.
- `on_start` Result confirmation callback (for request/start operations).
- `cookie` Callback context for `on_start`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_start
```c
int media_uv_player_start(void* handle, media_uv_callback on_start, void* cookie);
```
Plays or resumes the prepared resource.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_start` Result callback function.
- `cookie` Callback context for `on_start`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_pause
```c
int media_uv_player_pause(void* handle, media_uv_callback on_pause, void* cookie);
```
Pauses playback.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_pause` Result callback function.
- `cookie` Callback context for `on_pause`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_stop
```c
int media_uv_player_stop(void* handle, media_uv_callback on_stop, void* cookie);
```
Stops playback and clears the prepared audio source.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_stop` Result callback function.
- `cookie` Callback context for `on_stop`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_set_volume
```c
int media_uv_player_set_volume(void* handle, float volume, media_uv_callback on_volume, void* cookie);
```
Sets the player volume.
**Parameters**:
- `handle` Asynchronous player handle.
- `volume` Volume value in the range `[0.0, 1.0]`.
- `on_volume` Result callback function.
- `cookie` Callback context for `on_volume`.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_uv_player_get_volume
```c
int media_uv_player_get_volume(void* handle, media_uv_float_callback on_volume, void* cookie);
```
Gets the player volume.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_volume` Result callback function.
- `cookie` Callback context for `on_volume`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_get_playing
```c
int media_uv_player_get_playing(void* handle, media_uv_int_callback on_playing, void* cookie);
```
Gets the current playing status.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_playing` Result callback function.
- `cookie` Callback context for `on_playing`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_get_position
```c
int media_uv_player_get_position(void* handle, media_uv_unsigned_callback on_position, void* cookie);
```
Gets the current playback position.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_position` Result callback function.
- `cookie` Callback context for `on_position`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_get_duration
```c
int media_uv_player_get_duration(void* handle, media_uv_unsigned_callback on_duration, void* cookie);
```
Gets the duration of the current audio source.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_duration` Result callback function.
- `cookie` Callback context for `on_duration`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_get_latency
```c
int media_uv_player_get_latency(void* handle, media_uv_unsigned_callback cb, void* cookie);
```
Gets the latency of the current audio source.
**Parameters**:
- `handle` Asynchronous player handle.
- `cb` Result callback function.
- `cookie` Callback context for `cb`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_set_looping
```c
int media_uv_player_set_looping(void* handle, int loop, media_uv_callback on_looping, void* cookie);
```
Sets the loop count.
**Parameters**:
- `handle` Asynchronous player handle.
- `loop` Loop count; `-1` means infinite looping.
- `on_looping` Result callback function.
- `cookie` Callback context for `on_looping`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_seek
```c
int media_uv_player_seek(void* handle, unsigned int position, media_uv_callback on_seek, void* cookie);
```
Seeks to the specified position from the beginning.
**Parameters**:
- `handle` Asynchronous player handle.
- `position` Target position in milliseconds.
- `on_seek` Result callback function.
- `cookie` Callback context for `on_seek`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_set_property
```c
int media_uv_player_set_property(void* handle, const char* target, const char* key, const char* value, media_uv_callback on_setprop, void* cookie);
```
Sets a property on the player.
**Parameters**:
- `handle` Asynchronous player handle.
- `target` Target filter name.
- `key` Property key.
- `value` Property value.
- `on_setprop` Result callback function.
- `cookie` Callback context for `on_setprop`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_get_property
```c
int media_uv_player_get_property(void* handle, const char* target, const char* key, media_uv_string_callback on_getprop, void* cookie);
```
Gets a property from the player.
**Parameters**:
- `handle` Asynchronous player handle.
- `target` Target filter name.
- `key` Property key.
- `on_getprop` Result callback function.
- `cookie` Callback context for `on_getprop`.
**Returns**:
Returns `0` on success, or a negated errno on failure.
### media_uv_player_query
```c
int media_uv_player_query(void* handle, media_uv_object_callback on_query, void* cookie);
```
Queries metadata of the player.
**Parameters**:
- `handle` Asynchronous player handle.
- `on_query` Callback function that receives the metadata pointer.
- `cookie` Callback context for `on_query`.
**Returns**:
Returns 0 on success, or a negated error code on failure.
### media_uv_player_close_socket
```c
int media_uv_player_close_socket(void* handle);
```
Closes the socket file descriptor.
**Parameters**:
- `handle` Player handle.
**Returns**:
Returns 0 on success, or a negated error code on failure.

File diff suppressed because it is too large Load Diff

View File

@ -1,545 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_recorder.md) \]
# Media Recorder API
Audio/video recording functionality, supporting file recording and buffer mode.
Header: `#include <media_recorder.h>`
## openvela Implementation Notes
- **Synchronous/Asynchronous dual model**: `media_recorder_*` (synchronous) and `media_uv_recorder_*` (asynchronous, based on libuv)
- **Output methods**: Two destination types are supported
- Local file: Specify the path via `prepare(url)`
- Byte stream buffer: Read via `read_data`, or obtain the underlying socket via `get_socket`
- **Photo capture**: In addition to audio/video recording, provides `take_picture` / `start_picture` / `finish_picture` image capture interfaces
- **Event callback**: Register an event listener via `set_event_callback`
## Synchronous Interface - Lifecycle
### media_recorder_open
```c
void* media_recorder_open(const char* params);
```
Opens a recorder with the specified source type.
**Parameters**:
- `params` Source type constant, typically `MEDIA_SOURCE_MIC`.
**Returns**:
Returns the recorder handle on success; returns `NULL` on failure.
### media_recorder_close
```c
int media_recorder_close(void* handle);
```
Closes the recorder.
**Parameters**:
- `handle` Recorder handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_set_event_callback
```c
int media_recorder_set_event_callback(void* handle, void* cookie, media_event_callback event_cb);
```
Sets the recorder event callback, which is invoked on state changes or other events of interest.
**Parameters**:
- `handle` Recorder handle.
- `cookie` User data passed back when `event_cb` is triggered.
- `event_cb` Event callback function.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_prepare
```c
int media_recorder_prepare(void* handle, const char* url, const char* options);
```
Prepares the recorder.
**Parameters**:
- `handle` Recorder handle.
- `url` Resource path, supporting two modes: 1. URL mode: `url` is a local file path; the framework opens and records to that path. 2. BUFFER mode: `url` is `NULL`; the caller must continuously receive data via `media_recorder_read_data()` or `media_recorder_get_socket()` + `read()`.
- `options` Additional configuration parameters, including: format (container format, e.g. opus/wav), sample_rate (sample rate), ch_layout (channel layout), b (bitrate, e.g. `"23900"`), vbr (0=constant bitrate, 1=variable bitrate), level (encoding complexity, 0-10, default 10). Example: `"format=opusraw:sample_rate=16000:ch_layout=mono:b=32000:vbr=0:level=1"`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_reset
```c
int media_recorder_reset(void* handle);
```
Resets the recorder.
**Parameters**:
- `handle` Recorder handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Synchronous Interface - Data Stream
### media_recorder_read_data
```c
ssize_t media_recorder_read_data(void* handle, void* data, size_t len);
```
Reads recorded data from the recorder.
**Parameters**:
- `handle` Recorder handle.
- `data` Buffer address.
- `len` Buffer length.
**Returns**:
Returns the number of bytes read on success, or a negative errno on failure.
### media_recorder_get_sockaddr
```c
int media_recorder_get_sockaddr(void* handle, struct sockaddr_storage* addr);
```
Gets the socket address information for buffer mode.
**Parameters**:
- `handle` Recorder handle.
- `addr` Socket address information output.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_get_socket
```c
int media_recorder_get_socket(void* handle);
```
Gets the socket file descriptor for reading.
**Parameters**:
- `handle` Recorder handle.
**Returns**:
Returns the socket file descriptor on success, or a negative errno on failure.
### media_recorder_close_socket
```c
void media_recorder_close_socket(void* handle);
```
Closes the socket file descriptor when the recorder finishes receiving data.
**Parameters**:
- `handle` Recorder handle.
## Synchronous Interface - Recording Control
### media_recorder_start
```c
int media_recorder_start(void* handle);
```
Starts or resumes recording from the audio source.
**Parameters**:
- `handle` Recorder handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_pause
```c
int media_recorder_pause(void* handle);
```
Pauses the recorder after capture has started.
**Parameters**:
- `handle` Recorder handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_stop
```c
int media_recorder_stop(void* handle);
```
Stops recording.
**Parameters**:
- `handle` Recorder handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Synchronous Interface - Properties
### media_recorder_set_property
```c
int media_recorder_set_property(void* handle, const char* target, const char* key, const char* value);
```
Sets a property on the recorder path.
**Parameters**:
- `handle` Recorder handle.
- `target` Target filter name.
- `key` Property key to set.
- `value` Property value to set.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_get_property
```c
int media_recorder_get_property(void* handle, const char* target, const char* key, char* value, int value_len);
```
Gets a property from the recorder path.
**Parameters**:
- `handle` Recorder handle.
- `target` Target filter name.
- `key` Property key to query.
- `value` Output buffer.
- `value_len` Length of the output buffer.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Synchronous Interface - Image Capture
### media_recorder_take_picture
```c
int media_recorder_take_picture(char* params, char* filename, size_t number);
```
Takes a picture from the camera.
**Parameters**:
- `params` Camera open path parameters.
- `filename` Storage path for the new image.
- `number` Number of pictures to take.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_recorder_start_picture
```c
void* media_recorder_start_picture(char* params, char* filename, size_t number, media_event_callback event_cb, void* cookie);
```
Starts taking a picture, including open, set_event_callback, prepare, and start operations.
**Parameters**:
- `params` Open parameters.
- `filename` Storage path for the new image.
- `number` Number of pictures to take.
- `event_cb` Callback function for handling status feedback.
- `cookie` User private data.
**Returns**:
Returns a valid handle on success, or `NULL` on failure.
### media_recorder_finish_picture
```c
int media_recorder_finish_picture(void* handle);
```
Closes the recorder when picture taking is finished.
**Parameters**:
- `handle` Recorder handle returned by `media_recorder_start_picture()`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Asynchronous Interface (libuv-based)
The following interfaces are only available when `CONFIG_LIBUV` is enabled.
### media_uv_recorder_open
```c
void* media_uv_recorder_open(void* loop, const char* source, media_uv_callback on_open, void* cookie);
```
Opens an asynchronous recorder.
**Parameters**:
- `loop` The `uv_loop_t*` event loop handle of the current thread.
- `source` Source type.
- `on_open` Callback function triggered after open completes.
- `cookie` Callback context shared by `on_open`, `on_event`, and `on_close`.
**Returns**:
Returns the recorder handle on success.
### media_uv_recorder_listen
```c
int media_uv_recorder_listen(void* handle, media_event_callback on_event);
```
Listens for status change events by setting a callback.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `on_event` Event callback function, invoked upon notification.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_close
```c
int media_uv_recorder_close(void* handle, media_uv_callback on_close);
```
Closes the asynchronous recorder.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `on_close` Callback function triggered after resource release completes.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_prepare
```c
int media_uv_recorder_prepare(void* handle, const char* url, const char* options, media_uv_object_callback on_connection, media_uv_callback on_prepare, void* cookie);
```
Prepares the destination file.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `url` Destination path.
- `options` Destination configuration parameters; see `media_recorder_prepare` for details.
- `on_connection` Connection callback; in BUFFER mode, carries a writable `uv_pipe_t`.
- `on_prepare` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_start_auto
```c
int media_uv_recorder_start_auto(void* handle, const char* stream, media_uv_callback on_start, void* cookie);
```
Starts or resumes capturing with an automatic focus request.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `stream` Scenario constant defined in `media_defs.h`.
- `on_start` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_start
```c
int media_uv_recorder_start(void* handle, media_uv_callback on_start, void* cookie);
```
Starts or resumes capturing.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `on_start` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_pause
```c
int media_uv_recorder_pause(void* handle, media_uv_callback on_pause, void* cookie);
```
Pauses capturing.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `on_pause` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_stop
```c
int media_uv_recorder_stop(void* handle, media_uv_callback on_stop, void* cookie);
```
Stops capturing and finishes the destination file.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `on_stop` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_set_property
```c
int media_uv_recorder_set_property(void* handle, const char* target, const char* key, const char* value, media_uv_callback cb, void* cookie);
```
Sets a property on the recorder.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `target` Target filter name.
- `key` Property key.
- `value` Property value.
- `cb` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_get_property
```c
int media_uv_recorder_get_property(void* handle, const char* target, const char* key, media_uv_string_callback cb, void* cookie);
```
Gets a property from the recorder.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `target` Target filter name.
- `key` Property key.
- `cb` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_reset
```c
int media_uv_recorder_reset(void* handle, media_uv_callback on_reset, void* cookie);
```
Resets the recorder, clearing the current recording to start a new one.
**Parameters**:
- `handle` Asynchronous recorder handle.
- `on_reset` Result callback function.
- `cookie` One-time callback context.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_recorder_take_picture
```c
int media_uv_recorder_take_picture(void* loop, char* params, char* filename, size_t number, media_uv_callback on_complete, void* cookie);
```
Takes a picture from the camera.
**Parameters**:
- `loop` The `uv_loop_t*` event loop handle of the current thread.
- `params` Camera open path parameters.
- `filename` Storage path for the new image.
- `number` Number of pictures to take.
- `on_complete` Result callback function.
- `cookie` User private data.
**Returns**:
Returns `0` on success, or a negative errno on failure.

View File

@ -1,810 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_session.md) \]
# Media Session API
Media playback control and state synchronization, supporting the controller-controllee model.
Header: `#include <media_session.h>`
## openvela Implementation Notes
- **Controller-controllee model**: Supports two roles
- Controller: Opened via `media_session_open`, sends playback control commands to the currently active media
- Controllee: Registered via `media_session_register`, receives control commands and reports state
- **Synchronous/asynchronous dual model**: `media_session_*` (synchronous) and `media_uv_session_*` (asynchronous, based on libuv)
- **Control commands**: start / stop / pause / seek / prev_song / next_song / volume, etc.
- **State queries**: The controller can query the current playback state, position, duration, volume, etc.
- **State notifications**: The controllee pushes playback state changes to the controller via `notify` / `update`
## Controller Interfaces - Lifecycle
### media_session_open
```c
void* media_session_open(const char* params);
```
Open a media session controller.
**Parameters**:
- `params` NULL, currently unused.
**Returns**:
void* The controller handle, or NULL on failure.
### media_session_close
```c
int media_session_close(void* handle);
```
Close a media session controller.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_set_event_callback
```c
int media_session_set_event_callback(void* handle, void* cookie, media_event_callback on_event);
```
Set an event callback to receive messages from the controllee.
**Parameters**:
- `handle` Controller handle.
- `cookie` Callback argument for `on_event`.
- `on_event` Event callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Controller Interfaces - Playback Control
### media_session_start
```c
int media_session_start(void* handle);
```
Request to start playback.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_stop
```c
int media_session_stop(void* handle);
```
Request to stop playback.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_pause
```c
int media_session_pause(void* handle);
```
Request to pause playback.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_seek
```c
int media_session_seek(void* handle, unsigned position);
```
Request to seek to the specified position.
**Parameters**:
- `handle` Controller handle.
- `position` Start position, in milliseconds.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_prev_song
```c
int media_session_prev_song(void* handle);
```
Request to play the previous song.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_next_song
```c
int media_session_next_song(void* handle);
```
Request to play the next song.
**Parameters**:
- `handle` Controller handle.
## Controller Interfaces - Volume Control
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_increase_volume
```c
int media_session_increase_volume(void* handle);
```
Request to increase the volume.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_decrease_volume
```c
int media_session_decrease_volume(void* handle);
```
Request to decrease the volume.
**Parameters**:
- `handle` Controller handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_set_volume
```c
int media_session_set_volume(void* handle, int volume);
```
Request to set the volume.
**Parameters**:
- `handle` Controller handle.
- `volume` Volume level.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Controller Interfaces - State Queries
### media_session_query
```c
int media_session_query(void* handle, const media_metadata_t** data);
```
Query metadata from the most active controllee.
**Parameters**:
- `handle` Controller handle.
- `data` Output pointer to receive the metadata pointer.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_session_get_state
```c
int media_session_get_state(void* handle, int* state);
```
Get the overall status.
**Parameters**:
- `handle` Controller handle.
- `state` Current state.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_session_get_position
```c
int media_session_get_position(void* handle, unsigned* position);
```
Get the current position in milliseconds.
**Parameters**:
- `handle` Controller handle.
- `position` Current position, in milliseconds.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_session_get_duration
```c
int media_session_get_duration(void* handle, unsigned* duration);
```
Get the total duration in milliseconds.
**Parameters**:
- `handle` Controller handle.
- `duration` Current total duration, in milliseconds.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_session_get_volume
```c
int media_session_get_volume(void* handle, int* volume);
```
Get the current volume index.
**Parameters**:
- `handle` Controller handle.
- `volume` Volume level.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Controllee Interfaces
### media_session_register
```c
void* media_session_register(void* cookie, media_event_callback on_event);
```
Register as a session controllee.
**Parameters**:
- `cookie` Callback argument of `on_event`.
- `on_event` Event callback function.
**Returns**:
Returns the controllee handle on success, or NULL on failure.
### media_session_unregister
```c
int media_session_unregister(void* handle);
```
Unregister the session controllee.
**Parameters**:
- `handle` Controllee handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_notify
```c
int media_session_notify(void* handle, int event, int result, const char* extra);
```
Notify the result of a control message. After receiving MEDIA_EVENT_* from `on_event`, as the controllee you should handle the control message; after acknowledging it, call this API to send the response to the controller.
**Parameters**:
- `handle` Controllee handle.
- `event` MEDIA_EVENT_*
- `result` Operation result; `0` on success, a negative errno on failure.
- `extra` Additional message.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_session_update
```c
int media_session_update(void* handle, const media_metadata_t* data);
```
Update metadata to the session.
**Parameters**:
- `handle` Controllee handle.
- `data` Metadata to update.
## Asynchronous Interfaces (libuv-based)
The following interfaces are available only when `CONFIG_LIBUV` is enabled; both the controller and the controllee have corresponding asynchronous versions.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_open
```c
void* media_uv_session_open(void* loop, char* params, media_uv_callback on_open, void* cookie);
```
Open an async session controller.
**Parameters**:
- `loop` The `uv_loop_t*` event loop handle of the current thread.
- `params` Currently unused.
- `on_open` Callback triggered after opening completes.
- `cookie` Callback context shared by `on_open`, `on_event`, and `on_close`.
**Returns**:
Returns the async controller handle on success.
### media_uv_session_close
```c
int media_uv_session_close(void* handle, media_uv_callback on_close);
```
Close the async controller handle.
**Parameters**:
- `handle` Async controller handle to destroy.
- `on_close` Callback triggered after closing completes.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_listen
```c
int media_uv_session_listen(void* handle, media_event_callback on_event);
```
Listen to events from the controllee.
**Parameters**:
- `handle` Async controller handle.
- `on_event` Event callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_start
```c
int media_uv_session_start(void* handle, media_uv_callback on_start, void* cookie);
```
Request to start playback.
**Parameters**:
- `handle` Async controller handle.
- `on_start` Result callback function.
- `cookie` Callback argument of `on_start`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_stop
```c
int media_uv_session_stop(void* handle, media_uv_callback on_stop, void* cookie);
```
Request to stop playback.
**Parameters**:
- `handle` Async controller handle.
- `on_stop` Result callback function.
- `cookie` Callback argument of `on_stop`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_pause
```c
int media_uv_session_pause(void* handle, media_uv_callback on_pause, void* cookie);
```
Request to pause playback.
**Parameters**:
- `handle` Async controller handle.
- `on_pause` Result callback function.
- `cookie` Callback argument of `on_pause`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_seek
```c
int media_uv_session_seek(void* handle, unsigned position, media_uv_callback on_seek, void* cookie);
```
Request to seek to the specified position.
**Parameters**:
- `handle` Player handle.
- `position` Start position, in milliseconds.
- `on_seek` Result callback function.
- `cookie` Callback argument of `on_seek`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_prev_song
```c
int media_uv_session_prev_song(void* handle, media_uv_callback on_pre_song, void* cookie);
```
Request to play the previous song.
**Parameters**:
- `handle` Async controller handle.
- `on_prev` Result callback function.
- `cookie` Callback argument of `on_prev`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_next_song
```c
int media_uv_session_next_song(void* handle, media_uv_callback on_next, void* cookie);
```
Request to play the next song.
**Parameters**:
- `handle` Async controller handle.
- `on_next` Result callback function.
- `cookie` Callback argument of `on_next`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_increase_volume
```c
int media_uv_session_increase_volume(void* handle, media_uv_callback on_increase, void* cookie);
```
Request to increase the volume.
**Parameters**:
- `handle` Async controller handle.
- `on_increase` Result callback function.
- `cookie` Callback argument of `on_increase`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_decrease_volume
```c
int media_uv_session_decrease_volume(void* handle, media_uv_callback on_decrease, void* cookie);
```
Request to decrease the volume.
**Parameters**:
- `handle` Async controller handle.
- `on_decrease` Result callback function.
- `cookie` Callback argument of `on_decrease`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_set_volume
```c
int media_uv_session_set_volume(void* handle, int volume, media_uv_callback on_set_volume, void* cookie);
```
Request to set the volume.
**Parameters**:
- `handle` Async controller handle.
- `Volume` Volume level.
- `on_volume` Result callback function.
- `cookie` Callback argument of `on_volume`.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_query
```c
int media_uv_session_query(void* handle, media_uv_object_callback on_query, void* cookie);
```
Query the full state information.
**Parameters**:
- `handle` Async controller handle.
- `on_query` Callback that receives the metadata pointer.
- `cookie` Callback argument.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_get_state
```c
int media_uv_session_get_state(void* handle, media_uv_int_callback on_state, void* cookie);
```
Get the current state.
**Parameters**:
- `handle` Async controller handle.
- `on_state` Result callback function.
- `cookie` Callback argument of `on_state`.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_get_position
```c
int media_uv_session_get_position(void* handle, media_uv_unsigned_callback on_position, void* cookie);
```
Get the current playback position.
**Parameters**:
- `handle` Async controller handle.
- `on_position` Result callback function.
- `cookie` Callback argument of `on_position`.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_get_duration
```c
int media_uv_session_get_duration(void* handle, media_uv_unsigned_callback on_duration, void* cookie);
```
Get the current duration.
**Parameters**:
- `handle` Async controller handle.
- `on_duration` Result callback function.
- `cookie` Callback argument of `on_duration`.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_get_volume
```c
int media_uv_session_get_volume(void* handle, media_uv_int_callback on_get_volume, void* cookie);
```
Get the current volume.
**Parameters**:
- `handle` Async controller handle.
- `on_volume` Result callback function.
- `cookie` Callback argument of `on_volume`.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### media_uv_session_register
```c
void* media_uv_session_register(void* loop, const char* params, media_event_callback on_event, void* cookie);
```
Register as a session controllee to receive control messages.
**Parameters**:
- `loop` The `uv_loop_t*` event loop handle of the current thread.
- `params` Unused; pass `NULL`.
- `on_event` Callback to receive control messages.
- `cookie` Callback argument.
**Returns**:
void* Async controllee handle, or NULL on failure.
### media_uv_session_unregister
```c
int media_uv_session_unregister(void* handle, media_uv_callback on_release);
```
Unregister self.
**Parameters**:
- `handle` Async controllee handle.
- `on_release` Resource release callback for the caller.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_notify
```c
int media_uv_session_notify(void* handle, int event, int result, const char* extra, media_uv_callback on_notify, void* cookie);
```
Notify the result of a control message. After receiving MEDIA_EVENT_* from `on_event`, as the controllee you should handle the control message; after acknowledging it, call this API to send the response to the controller.
**Parameters**:
- `handle` Async controllee handle.
- `event` The event to notify.
- `result` Event result; usually `0` on success, a negative errno on failure.
- `extra` Additional string message for the event; pass `NULL` when not needed.
- `on_notify` Notification acknowledgment callback.
- `cookie` Callback argument.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_uv_session_update
```c
int media_uv_session_update(void* handle, const media_metadata_t* data, media_uv_callback on_update, void* cookie);
```
Update metadata to the session.
**Parameters**:
- `handle` Async controllee handle.
- `data` Metadata to update.
- `on_update` Update acknowledgment callback.
- `cookie` Callback argument.
**Returns**:
Returns `0` on success, or a negative errno on failure.

View File

@ -1,189 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_trigger.md) \]
# Media Trigger API
Media Trigger is used for Voice Trigger scenarios, enabling keyword detection and recognition through loading acoustic models.
Header: `#include <media_trigger.h>`
## openvela Implementation Notes
- **Typical Scenarios**: Voice wake-up on smart speakers, smartwatches, etc.
- **Workflow**:
1. `open` to open a trigger handle
2. `set_event_callback` to register an event callback
3. `load_sound_model` to load an acoustic model
4. `start_recognition` to start recognition
5. Listen for callbacks and process when a keyword is detected
6. `stop_recognition``unload_sound_model``close` for cleanup
- **Parameter Configuration**: The `params` passed to `open` selects the microphone configuration (e.g. `"default"` / `"Dual Mic"`)
- **Underlying Implementation**: Interfaces with the DSP-side acoustic model processor
## Trigger Lifecycle
### media_trigger_open
```c
void* media_trigger_open(const char* params);
```
Opens a media trigger handle.
**Parameters**:
- `params` Trigger parameter string, e.g. `"default"` or `"Dual Mic"`, used to select the microphone configuration.
**Returns**:
Returns the trigger handle on success, or `NULL` on failure.
**Example**:
```c
// 1. Create instance
void* handle = media_trigger_open("default");
// 2. Set event callback
ret = media_trigger_set_event_callback(handle, cookie, callback);
// 3. Load acoustic model
ret = media_trigger_load_sound_model(handle, model, model_size);
// 4. Start recognition
ret = media_trigger_start_recognition(handle);
// 5. Stop recognition
ret = media_trigger_stop_recognition(handle);
// 6. Unload model
ret = media_trigger_unload_sound_model(handle);
// 7. Close handle
ret = media_trigger_close(handle);
```
### media_trigger_close
```c
int media_trigger_close(void* handle);
```
Closes the trigger handle and releases associated resources.
**Parameters**:
- `handle` The trigger handle to close.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Events and Callbacks
### media_trigger_set_event_callback
```c
int media_trigger_set_event_callback(void* handle, void* event_cookie,
media_event_callback on_event);
```
Sets an event callback for the trigger to receive events such as recognition state changes.
**Parameters**:
- `handle` Trigger handle.
- `event_cookie` User data passed to the callback.
- `on_event` Event callback function.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Acoustic Model Management
### media_trigger_load_sound_model
```c
int media_trigger_load_sound_model(void* handle, void* model, size_t model_size);
```
Loads acoustic model data for the trigger.
**Parameters**:
- `handle` Trigger handle.
- `model` Pointer to acoustic model data.
- `model_size` Size of the model data in bytes.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_trigger_unload_sound_model
```c
int media_trigger_unload_sound_model(void* handle);
```
Unloads the currently loaded acoustic model.
**Parameters**:
- `handle` Trigger handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## Recognition Control
### media_trigger_start_recognition
```c
int media_trigger_start_recognition(void* handle);
```
Starts voice recognition. The trigger continuously detects input audio and matches keywords in the loaded model.
**Parameters**:
- `handle` Trigger handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
### media_trigger_stop_recognition
```c
int media_trigger_stop_recognition(void* handle);
```
Stops voice recognition.
**Parameters**:
- `handle` Trigger handle.
**Returns**:
Returns `0` on success, or a negative errno on failure.
## DSP Property Query
### media_trigger_get_property
```c
int media_trigger_get_property(char* properties, int len);
```
Queries property information of the underlying DSP for the trigger.
**Parameters**:
- `properties` Output buffer for receiving the property string.
- `len` Buffer length.
**Returns**:
Returns `0` on success, or a negative errno on failure.

View File

@ -1,107 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_trigger_model.md) \]
# Sound Model API
The Sound Model interface handles low-level acoustic model data required by the media trigger, providing model loading, unloading, property/option queries, and hotword detection capabilities.
Header: `#include <media_trigger_model.h>`
## openvela Implementation Notes
- **Relationship with Media Trigger**: `media_trigger_*` is the high-level voice wakeup interface (including DSP path), while `media_trigger_model_*` is the low-level model operation interface (no audio capture involved)
- **Typical Usage**: Custom recognition flows, running one-shot keyword detection on a specific PCM buffer
- **Model Properties/Options**: Use `get_properties` to query vendor properties, and `get_options` to read recommended audio sampling parameters
- **One-shot Detection**: `detect_hotword` performs a single synchronous detection on a given PCM buffer
## Model Lifecycle
### media_trigger_model_load
```c
void* media_trigger_model_load(const void* model, size_t size);
```
Loads acoustic model data and returns a model context.
**Parameters**:
- `model` Pointer to the start of model data.
- `size` Size of the model data in bytes.
**Returns**:
Returns the model context pointer on success, or `NULL` on failure.
### media_trigger_model_unload
```c
void media_trigger_model_unload(void* context);
```
Unloads a previously loaded model context.
**Parameters**:
- `context` The model context to unload.
## Model Property Queries
### media_trigger_model_get_properties
```c
void media_trigger_model_get_properties(void* properties, size_t* size);
```
Queries vendor-provided model property information.
**Parameters**:
- `properties` Output buffer for storing property data.
- `size` Input/output parameter: on entry specifies the buffer size, on return updated to the actual number of bytes written.
### media_trigger_model_get_options
```c
void media_trigger_model_get_options(void* context, char* options, size_t size);
```
Queries the model's recommended audio capture options string, e.g. `"format=s16le:sample_rate=16000:ch_layout=mono"`.
**Parameters**:
- `context` Model context (returned by `media_trigger_model_load`).
- `options` Output buffer for receiving the options string.
- `size` Output buffer size in bytes.
### media_trigger_model_get_buffer_size
```c
void media_trigger_model_get_buffer_size(void* context, size_t* size);
```
Queries the model's recommended recording buffer size.
**Parameters**:
- `context` Model context.
- `size` Output parameter, returns the recommended buffer size in bytes.
## Hotword Detection
### media_trigger_model_detect_hotword
```c
bool media_trigger_model_detect_hotword(void* context, const char* buffer, size_t size);
```
Runs a single model detection pass on the given PCM buffer to determine whether a hotword is matched.
**Parameters**:
- `context` Model context.
- `buffer` PCM audio buffer to analyze.
- `size` Buffer size in bytes.
**Returns**:
Returns `true` if a hotword is detected, `false` otherwise.

View File

@ -1,154 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/media/media_utils.md) \]
# Media Utils API
General utility interfaces for the media framework, including DTMF dual-tone multi-frequency signal generation, event name lookup, graph/policy dump, and generic command sending.
Header: `#include <media_utils.h>`
## openvela Implementation Notes
- **DTMF**: Generates DTMF dual-tone multi-frequency signals for `0-9` / `*#ABCD` keys, with a fixed audio format of `format=s16le:sample_rate=8000:ch_layout=mono` (defined by the `MEDIA_TONE_DTMF_FORMAT` macro)
- **Debug Interfaces**: `media_graph_dump`, `media_player_dump`, `media_recorder_dump` and `media_policy_dump` print internal state for troubleshooting
- **Generic Command**: `media_process_command` sends custom commands to the media server for extended capabilities (e.g., triggering an operation on a specific filter within a graph)
- **Event Name Lookup**: `media_event_get_name` converts `MEDIA_EVENT_*` numeric values to human-readable strings for log output
## DTMF Signal Generation
### media_dtmf_get_buffer_size
```c
int media_dtmf_get_buffer_size(const char* numbers);
```
Queries the buffer size required for DTMF signal generation.
**Parameters**:
- `numbers` Dial key character sequence, with characters in the range `0-9` and `*#ABCD`.
**Returns**:
Returns the buffer size in bytes on success, or a negative errno on failure.
### media_dtmf_generate
```c
int media_dtmf_generate(const char* numbers, void* buffer);
```
Generates one or more consecutive DTMF signals and writes them into the caller-provided buffer.
**Parameters**:
- `numbers` Dial key character sequence, with characters in the range `0-9` and `*#ABCD`.
- `buffer` Output buffer; its size should be queried in advance via `media_dtmf_get_buffer_size`.
**Returns**:
Returns `0` on success, or a negative errno on failure.
**Notes**:
- When playing DTMF tones, the audio parameters must be fixed to `MEDIA_TONE_DTMF_FORMAT` (`s16le / 8000Hz / mono`).
## Event Name Lookup
### media_event_get_name
```c
const char* media_event_get_name(int event);
```
Converts a `MEDIA_EVENT_*` enum value to a human-readable string.
**Parameters**:
- `event` Event value, one of the `MEDIA_EVENT_*` constants.
**Returns**:
Always returns a printable string; returns a placeholder string for unknown events (never returns `NULL`).
**Example**:
```c
printf("event: %s\n", media_event_get_name(MEDIA_EVENT_STARTED));
// Output: event: STARTED
```
## Dump Debugging
### media_graph_dump
```c
void media_graph_dump(const char* options);
```
Prints the internal state of the media graph for debugging.
**Parameters**:
- `options` Dump options string.
### media_policy_dump
```c
void media_policy_dump(const char* options);
```
Prints the current state of the media policy for debugging.
**Parameters**:
- `options` Dump options string.
### media_player_dump
```c
void media_player_dump(const char* options);
```
Prints the internal state of the media player for debugging.
**Parameters**:
- `options` Dump options string.
### media_recorder_dump
```c
void media_recorder_dump(const char* options);
```
Prints the internal state of the media recorder for debugging.
**Parameters**:
- `options` Dump options string.
## Generic Command
### media_process_command
```c
int media_process_command(const char* target, const char* cmd,
const char* arg, char* res, int res_len);
```
Sends a custom command to a specified graph filter instance within the media server.
**Parameters**:
- `target` Target graph filter instance name.
- `cmd` Command type.
- `arg` Command argument.
- `res` Response message output buffer.
- `res_len` Response buffer length.
**Returns**:
Returns `0` on success, or a negative errno on failure.

View File

@ -1,80 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/quickapp/basic.md) \]
# QuickApp Framework Introduction
The openvela QuickApp framework (hereinafter referred to as "application framework") is the [Quick App](https://doc.quickapp.cn/) runtime implementation on openvela. Compared to the mobile runtime, the openvela QuickApp framework has the following characteristics:
- Follows the Quick App Alliance standard, re-implemented for the openvela system, with some features and functionalities trimmed.
- Adapted for Real-Time Operating Systems (RTOS), focusing on runtime performance with high execution efficiency under low memory consumption.
- Easy to develop and deploy, effectively shortening the application development cycle.
This document introduces the overall design, implementation approach, and technical highlights of the application framework, rather than focusing on application development itself.
## Related Documentation
- [Xiaomi openvela QuickApp Development Manual](https://iot.mi.com/vela/quickapp/zh/content/intro.html) — Complete development guide for application developers
- [Feature Framework API](../feature/index.md) — Native extension APIs for QuickApp (JS and C/C++ interop)
## Build Configuration
The application framework itself has few configuration items, but has many dependencies. Among the dependencies, the renderer has the most requirements. For specific configuration, please refer to the documentation provided by the graphics team.
### Main Configuration
```kconfig
CONFIG_QUICKAPP_VAPP=y # QuickApp main configuration
CONFIG_QUICKAPP_VAPP_XMS=y # QuickApp xms integrated version, depends on xms service framework
CONFIG_QUICKAPP_LOG_LEVEL=1 # Log level, default INFO
CONFIG_QUICKAPP_MICRO_FRAMEWORK_MODE=y # Micro framework
CONFIG_QUICKAPP_PRIORITY=100 # Priority
CONFIG_HAP_APP_PATH="/data" # rpk installation path
CONFIG_QUICKAPP_THREADSTACKSIZE=1048576 # JS thread stack size
CONFIG_QUICKAPP_JSSTACKSIZE=524288 # JS engine stack size
CONFIG_QUICKAPP_JSHEAPSIZE=4194304 # JS engine heap memory limit, default 4MB for watch devices, adjust based on application complexity
CONFIG_CURL=y # Enable curl support, required for framework network feature
CONFIG_QUICKAPP_RPK_DIR="/resource/package" # AMS application installation path
CONFIG_QUICKAPP_BYTECODE_OPTIMIZATION=y # QuickJS bytecode optimization (string merging)
CONFIG_QUICKAPP_FOLME_ANIMENGINE_ADAPTER=n # folme animation engine
CONFIG_WIDGET_IMAGE_USE_CACHE_MANAGER=y # Enable widget image cache manager
# Font-related configuration
CONFIG_FONT_DEFAULT_NORMAL_NAME="MiSansW_Regular"
CONFIG_FONT_DEFAULT_BOLD_NAME="MiSansW_Demibold"
CONFIG_FONT_DEFAULT_SIZE=30
CONFIG_PROMPT_TOAST_FONT_SIZE=24
CONFIG_PROMPT_DIALOG_TITLE_FONT_SIZE=36
CONFIG_PROMPT_DIALOG_MSG_FONT_SIZE=34
```
### Debug Configuration
```kconfig
CONFIG_DOM_TRACE_ENABLE=n # vdom tree printing
CONFIG_JS_USE_SCHED_NOTE=n # Framework startup trace
CONFIG_QUICKAPP_MEMORY_STATUS=n # Framework JS engine memory info printing
CONFIG_WIDGET_LOG_ENABLE=y # LVGL widget log
CONFIG_WIDGET_LOG_LEVEL=1 # widget log level, default warning
CONFIG_WIDGET_ASSERT_ENABLE=n # widget assert
CONFIG_WIDGET_TRACE_ENABLE=n # widget trace check
CONFIG_WIDGET_PERF_ENABLE=n # widget performance monitor
CONFIG_WIDGET_DUMP_TREE_ENABLE=n # dump LVGL widget tree
CONFIG_WIDGET_DUMP_TREE_IN_LAYOUT=n # dump widget tree in layout task
CONFIG_WIDGET_SHOW_YOGA_NODE_ENABLE=n # widget show yoga node
CONFIG_WIDGET_DEBUG_DRAW_OUTLINE=n # widget draw outline for debug
CONFIG_CSS_ATTR_LIST_ENABLE=n # Enable widget get css/attr function
```
### Dependencies
```kconfig
CONFIG_LIBUV=y
CONFIG_LVGL_EXTENSION=y
CONFIG_LIBUV_EXTENSION=y
CONFIG_LVX_USE_FONT_MANAGER=y
CONFIG_LIB_YOGA=y
CONFIG_PROTOBUF_C=y
CONFIG_LIB_PNG=y
CONFIG_LV_USE_LIBPNG=y
CONFIG_LV_USE_NUTTX_LIBUV=y
CONFIG_USE_QUICKJS=y
```

View File

@ -1,7 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/quickapp/index.md) \]
# QuickApp Framework
The openvela QuickApp framework provides developers with a lightweight application runtime environment. It is based on the Quick App Alliance standard and adapted for Real-Time Operating System (RTOS) scenarios, supporting efficient execution with low memory consumption.
- **[Basic Interfaces](basic.md)** — Basic APIs for the QuickApp runtime

View File

@ -1,991 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/framework/security.md) \]
# Security Framework API
The openvela security framework is based on MiTEE (Trusted Execution Environment) and provides secure storage, key management, and secure payment capabilities, following the GlobalPlatform (GP) TEE standard.
This document covers:
- MiTEE CA application-level API (SST secure storage, triad, WeChat/Alipay payment, PIN)
- MiTEE Rootkey API
- GP TEE Client API (REE side, called by CA)
- GP TEE Internal API (TEE side, used by TA implementations)
Header files: Various CA headers under `frameworks/security/include/` (`comsst_ca_api.h` / `triad_ca_api.h`, etc.), as well as `<sys/boardctl.h>` (Rootkey), OP-TEE `<tee_client_api.h>` (TEE Client), and `<tee_internal_api.h>` (TEE Internal).
## openvela Implementation Notes
- **Dual security schemes**: openvela provides two optional security capabilities:
- **MiTEE-based TEE scheme** (main content of this document): For scenarios requiring hardware-level trusted execution environments
- **Android Keystore scheme** (see "Android Keystore Client API" section): Ported from AOSP, for lightweight scenarios requiring only key management and secure storage
- **Based on MiTEE**: openvela's TEE implementation, compatible with OP-TEE, following GlobalPlatform (GP) specifications
- **Two-side runtime**:
- **REE side** (Rich Execution Environment): Runs CA (Client Application), initiates TEE requests through `libteec`
- **TEE side** (Trusted Execution Environment): Runs TA (Trusted Application), scheduled by the `miteed` server
- **Communication channel**: Data exchange between CA and TA is performed via rpmsg socket
- **API layers**:
- Application-level CA API (located in `frameworks/security/ca/`) encapsulates common security operations (SST, triad, payment, PIN)
- GP TEE Client API (REE side) provides GP-standard Context/Session management and command invocation
- GP TEE Internal API (TEE side) provides memory/object/cryptographic capabilities callable by TA implementors
- **Key root**: Rootkey is written once during factory provisioning, immutable at runtime; all derived keys are derived from Rootkey
## Common Secure Storage SST CA API
Performs read/write operations on the Secure Storage (SST) partition. Implementation located in `frameworks/security/ca/comsst`.
### comsst_data_read
```c
uint32_t comsst_data_read(uint8_t *scope, uint8_t *name, bool is_deletable,
uint8_t *buff, uint32_t *out_len);
```
Reads a data record from the SST partition.
**Parameters**:
- `scope` Namespace (scope identifier) used to distinguish different services.
- `name` Record name.
- `is_deletable` Whether this record is allowed to be deleted by the user side.
- `buff` Output buffer to receive the read data.
- `out_len` Input/output parameter; input is the buffer size, output is the actual bytes read.
**Returns**:
Returns `TEE_SUCCESS` (`0`) on success, or a TEE error code on failure.
### comsst_data_write
```c
uint32_t comsst_data_write(uint8_t *scope, uint8_t *name, bool is_deletable,
uint8_t *buff, uint32_t len);
```
Writes a data record to the SST partition.
**Parameters**:
- `scope` Namespace.
- `name` Record name.
- `is_deletable` Whether this record is allowed to be deleted by the user side.
- `buff` Data buffer to write.
- `len` Data length.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### comsst_data_delete
```c
uint32_t comsst_data_delete(uint8_t *scope, uint8_t *name, bool is_deletable);
```
Deletes a record from the SST partition.
**Parameters**:
- `scope` Namespace.
- `name` Record name.
- `is_deletable` The deletable attribute of the record, must match the value used during write.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### is_comsst_data_exited
```c
uint32_t is_comsst_data_exited(uint8_t *scope, uint8_t *name, bool is_deletable);
```
Queries whether a specified record exists in the SST partition.
**Parameters**:
- `scope` Namespace.
- `name` Record name.
- `is_deletable` Deletable attribute.
**Returns**:
Returns `TEE_SUCCESS` if the record exists, or a corresponding error code if it does not.
### comsst_data_verify
```c
uint32_t comsst_data_verify(uint8_t *scope, uint8_t *name, bool is_deletable,
uint8_t *buff, uint32_t len);
```
Compares the provided data against the data already stored in SST. Commonly used to verify whether the application-side copy is up to date.
**Parameters**:
- `scope` Namespace.
- `name` Record name.
- `is_deletable` Deletable attribute.
- `buff` Data to compare.
- `len` Data length.
**Returns**:
Returns `TEE_SUCCESS` if the data matches, or an error code if it does not match or the operation fails.
## Triad CA API
Performs read/write operations on the device triad's Device ID (DID) and Key. Implementation located in `frameworks/security/ca/triad`.
### triad_store_did
```c
int triad_store_did(uint8_t *did, uint16_t len);
```
Writes the device DID to secure storage.
**Parameters**:
- `did` DID buffer.
- `len` DID length in bytes.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### triad_load_did
```c
int triad_load_did(uint8_t *did, uint16_t len);
```
Reads the DID from secure storage.
**Parameters**:
- `did` Output buffer to receive the DID.
- `len` Buffer length.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### triad_store_key
```c
int triad_store_key(uint8_t *key, uint16_t len);
```
Writes the device key to secure storage.
**Parameters**:
- `key` Key buffer.
- `len` Key length.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### triad_load_key
```c
int triad_load_key(uint8_t *key, uint16_t len);
```
Reads the device key from secure storage.
**Parameters**:
- `key` Output buffer.
- `len` Buffer length.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### triad_get_hmac
```c
int triad_get_hmac(uint8_t *input, uint16_t inlen,
uint8_t *output, uint16_t outlen);
```
Computes an HMAC over the input data using the device key, writing the result to the output buffer.
**Parameters**:
- `input` Input data.
- `inlen` Input data length.
- `output` Output buffer to receive the HMAC result.
- `outlen` Output buffer length.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## WeChat Pay CA API
Performs read/write operations on WeChat secure payment data. Implementation located in `frameworks/security/ca/wxcodepay`.
### wxcodepay_tee_data_read
```c
uint32_t wxcodepay_tee_data_read(int item, uint8_t *buff, uint32_t *out_len);
```
Reads a WeChat Pay data item.
**Parameters**:
- `item` Data item ID.
- `buff` Output buffer.
- `out_len` Input/output parameter, returns the actual bytes read.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### wxcodepay_tee_data_write
```c
uint32_t wxcodepay_tee_data_write(int item, const uint8_t *buf, uint32_t len);
```
Writes a WeChat Pay data item.
**Parameters**:
- `item` Data item ID.
- `buf` Data buffer.
- `len` Data length.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### wxcodepay_tee_data_delete
```c
uint32_t wxcodepay_tee_data_delete(int item);
```
Deletes the specified WeChat Pay data item.
**Parameters**:
- `item` Data item ID.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### is_wxcodepay_tee_data_exited
```c
bool is_wxcodepay_tee_data_exited(int item);
```
Queries whether the specified WeChat Pay data item is stored.
**Parameters**:
- `item` Data item ID.
**Returns**:
Returns `true` if the item exists, `false` otherwise.
## Alipay CA API
Performs read/write operations on Alipay secure payment data. Implementation located in `frameworks/security/ca/alipay`.
### alipay_tee_data_read
```c
uint32_t alipay_tee_data_read(const char *item_name, uint8_t *buff,
uint32_t *out_len);
```
Reads an Alipay data item.
**Parameters**:
- `item_name` Data item name string.
- `buff` Output buffer.
- `out_len` Input/output parameter, returns the actual bytes read.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### alipay_tee_data_write
```c
uint32_t alipay_tee_data_write(const char *item_name, const uint8_t *buf,
uint32_t len);
```
Writes an Alipay data item.
**Parameters**:
- `item_name` Data item name string.
- `buf` Data buffer.
- `len` Data length.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### alipay_tee_data_delete
```c
uint32_t alipay_tee_data_delete(const char *item_name);
```
Deletes the specified Alipay data item.
**Parameters**:
- `item_name` Data item name.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### is_alipay_tee_data_exited
```c
bool is_alipay_tee_data_exited(const char *item_name);
```
Queries whether the specified Alipay data item is stored.
**Parameters**:
- `item_name` Data item name.
**Returns**:
Returns `true` if the item exists, `false` otherwise.
## PIN CA API
Performs storage, verification, and modification operations on Personal Identification Numbers (PINs). Implementation located in `frameworks/security/ca/pin`.
### pin_store
```c
uint32_t pin_store(bool is_deletable, uint8_t *buff, uint32_t len);
```
Stores a PIN in secure storage.
**Parameters**:
- `is_deletable` Whether the PIN is allowed to be deleted by the user side.
- `buff` PIN data buffer.
- `len` PIN data length.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### pin_is_exist
```c
bool pin_is_exist(bool is_deletable);
```
Queries whether a PIN of the specified type is stored.
**Parameters**:
- `is_deletable` Deletable attribute, used to distinguish different types of PINs.
**Returns**:
Returns `true` if the PIN exists, `false` otherwise.
### pin_delete
```c
uint32_t pin_delete(bool is_deletable);
```
Deletes a PIN from secure storage.
**Parameters**:
- `is_deletable` Deletable attribute.
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
### pin_verify
```c
uint32_t pin_verify(bool is_deletable, uint8_t *buff, uint32_t len);
```
Verifies whether the PIN matches the record in secure storage.
**Parameters**:
- `is_deletable` Deletable attribute.
- `buff` PIN data to verify.
- `len` PIN data length.
**Returns**:
Returns `TEE_SUCCESS` if verification passes, or an error code if it fails.
### pin_change
```c
uint32_t pin_change(bool is_deletable, uint8_t *old, uint32_t oldlen,
uint8_t *new, uint32_t newlen);
```
Changes a stored PIN. Both the old PIN and new PIN must be provided.
**Parameters**:
- `is_deletable` Deletable attribute.
- `old` Old PIN buffer.
- `oldlen` Old PIN length.
- `new` New PIN buffer.
- `newlen` New PIN length.
**Returns**:
Returns `TEE_SUCCESS` on success (old PIN verified and new PIN written), or an error code on failure.
### pin_getsha256
```c
uint32_t pin_getsha256(bool is_deletable, uint8_t *buff, uint32_t len);
```
Retrieves the SHA-256 digest of the PIN.
**Parameters**:
- `is_deletable` Deletable attribute.
- `buff` Output buffer to receive the 32-byte digest.
- `len` Buffer length (must be at least 32).
**Returns**:
Returns `TEE_SUCCESS` on success, or a TEE error code on failure.
## MiTEE Rootkey Management
Rootkey is the **root of trust key** in the TEE security system, used to derive other keys. This key is written once during factory provisioning and read by the TEE OS at runtime.
### boardctl_BOARDIOC_UNIQUEKEY
```c
#include <sys/boardctl.h>
boardctl(BOARDIOC_UNIQUEKEY, tmp_key);
```
The TEE Server (`miteed`) in the TEE OS reads the Rootkey through the `boardctl` system call.
**Parameters**:
- `BOARDIOC_UNIQUEKEY` Fixed command identifier.
- `tmp_key` Output buffer pointer to receive the Rootkey content.
**Returns**:
Returns `0` on success, or a negative value on failure and sets `errno`.
**Notes**:
- Only the TEE OS side is allowed to call this interface; REE-side applications cannot access the Rootkey.
### rootkey_provision
```c
norflash_api_security_register_erase(HAL_FLASH_ID_0, 2048, 32);
norflash_api_security_register_write(HAL_FLASH_ID_0, 2048, rn, 32);
norflash_api_security_register_lock(HAL_FLASH_ID_0, 2048, 32);
```
Rootkey is written only in the factory build during the TEE OS first boot. The typical flow is "erase, write, lock":
**Parameters** (using `norflash_api_security_register_*` as example):
- `HAL_FLASH_ID_0` Flash device identifier.
- `2048` Security register start offset.
- `32` Byte length (256 bits).
- `rn` Rootkey data buffer provided during write.
**Notes**:
- Once `_lock` is executed, the region is permanently locked and cannot be written again. The correctness of the written data must be ensured.
- Production devices should never contain code that calls the above interfaces.
## Android Keystore Client API
**This section describes a Keystore that is independent of MiTEE**. The source code is ported from the Android Keystore service framework and follows the Keystore/Keymaster standard interfaces. The Keymaster layer supports multiple implementation backends, including MiTEE integration, pure software implementation, and implementations customized for Secure Elements (SE).
The openvela Keystore exposes a C API to upper layers, providing key management and secure storage capabilities for scenarios such as account SDKs. Users do not need to be aware of underlying hardware differences or storage details.
Header file: `#include <keystore/client.h>`
Source path: `external/android/system/security/keystore/`
### Keystore Usage Conventions
- **Storage unit**: Each data item is uniquely identified by a `name` string
- **Naming rules**: `name` length is limited to `CONFIG_NAME_MAX - 12`; if it contains special characters (ASCII `0` to `~` range), each character counts as 2 bytes
- **Return value convention**: All interfaces return `KEYSTORE_NO_ERROR` (value `1`) on success, and an error code greater than `1` on failure
- **Memory management**: Data returned by `keyStoreGet` is allocated internally; the caller must release it with `free()`
### keyStoreInsert
```c
int keyStoreInsert(const char *name, size_t nameLength,
const uint8_t *item, size_t itemLength);
```
Writes a data item to the Keystore. The data is encrypted internally within the Keystore.
**Parameters**:
- `name` Data item name. Must be unique, subject to the `CONFIG_NAME_MAX - 12` length limit.
- `nameLength` Name length in bytes.
- `item` Data buffer to write.
- `itemLength` Data length in bytes.
**Returns**:
Returns `KEYSTORE_NO_ERROR` on success, or another `KEYSTORE_*` error code on failure.
### keyStoreGet
```c
int keyStoreGet(const char *name, size_t nameLength,
uint8_t **item, size_t *itemLength);
```
Reads a data item from the Keystore by name. The data is allocated internally; the caller must release it with `free()`.
**Parameters**:
- `name` Data item name.
- `nameLength` Name length.
- `item` Output parameter, returns a pointer to the internally allocated data buffer.
- `itemLength` Output parameter, returns the data length.
**Returns**:
Returns `KEYSTORE_NO_ERROR` on success, or another `KEYSTORE_*` error code on failure.
### keyStoreDel
```c
int keyStoreDel(const char *name, size_t nameLength);
```
Deletes a data item from the Keystore by name.
**Parameters**:
- `name` Data item name.
- `nameLength` Name length.
**Returns**:
Returns `KEYSTORE_NO_ERROR` on success, or another `KEYSTORE_*` error code on failure.
### keyStoreExist
```c
int keyStoreExist(const char *name, size_t nameLength);
```
Checks whether a data item with the specified name exists in the Keystore.
**Parameters**:
- `name` Data item name.
- `nameLength` Name length.
**Returns**:
Returns `KEYSTORE_NO_ERROR` if the item exists, or another `KEYSTORE_*` error code if it does not exist or the operation fails.
### keyStoreReset
```c
int keyStoreReset(void);
```
Deletes **all** data items belonging to the current application in the Keystore.
**Returns**:
Returns `KEYSTORE_NO_ERROR` on success, or another `KEYSTORE_*` error code on failure.
**Notes**:
- This operation is irreversible and only affects the current application's namespace.
### Keystore Error Codes
Error codes returned by all Keystore interfaces (defined in header `keystore/client.h`):
| Error Code | Value | Description |
| --------------------------------------------------------- | ----- | --------------------------------------------- |
| `KEYSTORE_NO_ERROR` | 1 | Operation successful |
| `KEYSTORE_LOCKED` | 2 | Keystore is locked |
| `KEYSTORE_UNINITIALIZED` | 3 | Not initialized |
| `KEYSTORE_SYSTEM_ERROR` | 4 | System error |
| `KEYSTORE_PROTOCOL_ERROR` | 5 | Protocol error |
| `KEYSTORE_PERMISSION_DENIED` | 6 | Permission denied |
| `KEYSTORE_KEY_NOT_FOUND` | 7 | Specified data item does not exist |
| `KEYSTORE_VALUE_CORRUPTED` | 8 | Data corrupted |
| `KEYSTORE_UNDEFINED_ACTION` | 9 | Undefined action |
| `KEYSTORE_WRONG_PASSWORD_0` ~ `KEYSTORE_WRONG_PASSWORD_3` | 10-13 | Wrong password (up to 4 retries) |
| `KEYSTORE_SIGNATURE_INVALID` | 14 | Invalid signature |
| `KEYSTORE_OP_AUTH_NEEDED` | 15 | Authentication required before this operation |
| `KEYSTORE_KEY_ALREADY_EXISTS` | 16 | Data item already exists |
| `KEYSTORE_KEY_PERMANENTLY_INVALIDATED` | 17 | Data item permanently invalidated |
| `KEYSTORE_ABORT_CALLED` | 18 | Operation aborted |
| `KEYSTORE_PRUNED` | 19 | Data pruned |
| `KEYSTORE_BINDER_DIED` | 20 | Binder connection lost |
## GP TEE Client API (REE Side)
The following interfaces comply with the GlobalPlatform TEE Client API specification. They are called by CAs on the REE side to establish contexts with the TEE, open sessions, and execute commands.
### TEEC_InitializeContext
```c
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
```
Initializes a TEE context, establishing a connection between the CA and the specified TEE.
**Parameters**:
- `name` Null-terminated string identifying the TEE to connect to. The current implementation only supports `NULL`, indicating the default TEE.
- `context` Pointer to the context structure to initialize.
**Returns**:
Returns `TEEC_SUCCESS` on success, or another `TEEC_Result` error code on failure.
### TEEC_FinalizeContext
```c
void TEEC_FinalizeContext(TEEC_Context *context);
```
Destroys an initialized TEE context, closing the connection between the CA and the TEE.
**Parameters**:
- `context` The context to destroy.
**Notes**:
- All associated sessions must be closed and all shared memory must be released before calling this function.
### TEEC_OpenSession
```c
TEEC_Result TEEC_OpenSession(TEEC_Context *context,
TEEC_Session *session,
const TEEC_UUID *destination,
uint32_t connectionMethod,
const void *connectionData,
TEEC_Operation *operation,
uint32_t *returnOrigin);
```
Opens a new session between the CA and the specified TA.
**Parameters**:
- `context` An initialized TEE context.
- `session` Pointer to the session structure to initialize.
- `destination` UUID of the target TA.
- `connectionMethod` Connection method.
- `connectionData` Connection-related data (currently unused, should pass `NULL`).
- `operation` Operation parameter structure; pass `NULL` if no parameters are needed.
- `returnOrigin` Output parameter, returns the origin of the error when a failure occurs.
**Returns**:
Returns `TEEC_SUCCESS` on success, or another `TEEC_Result` error code on failure.
### TEEC_CloseSession
```c
void TEEC_CloseSession(TEEC_Session *session);
```
Closes an opened TA session.
**Parameters**:
- `session` The session to close.
### TEEC_InvokeCommand
```c
TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
uint32_t commandID,
TEEC_Operation *operation,
uint32_t *returnOrigin);
```
Invokes a TA command within the specified session.
**Parameters**:
- `session` An opened session handle.
- `commandID` The command ID internal to the TA.
- `operation` Operation parameter structure; pass `NULL` if no parameters are needed.
- `returnOrigin` Output parameter, returns the origin of the error when a failure occurs.
**Returns**:
Returns `TEEC_SUCCESS` on success, or another `TEEC_Result` error code on failure.
### TEEC_AllocateSharedMemory
```c
TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *sharedMem);
```
Allocates a block of shared memory within the specified TEE context.
**Parameters**:
- `context` An initialized TEE context.
- `sharedMem` Pointer to the shared memory structure to allocate.
**Returns**:
Returns `TEEC_SUCCESS` on success; returns `TEEC_ERROR_OUT_OF_MEMORY` if memory is insufficient; returns other `TEEC_Result` error codes for other failures.
### TEEC_RegisterSharedMemory
```c
TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
TEEC_SharedMemory *sharedMem);
```
Registers a **caller-allocated** memory block as shared memory. Unlike `TEEC_AllocateSharedMemory` (which allocates via the framework), this interface allows the CA to reuse an existing memory buffer as the TEE communication data area.
**Parameters**:
- `context` An initialized TEE context.
- `sharedMem` Pointer to the shared memory structure. The caller should pre-fill the `buffer`, `size`, and `flags` fields.
**Returns**:
Returns `TEEC_SUCCESS` on success, or a corresponding `TEEC_Result` error code on failure.
### TEEC_ReleaseSharedMemory
```c
void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMemory);
```
Releases or deregisters a previously allocated shared memory block. For memory allocated by `TEEC_AllocateSharedMemory`, the memory is freed. For memory registered by `TEEC_RegisterSharedMemory`, only deregistration is performed (the caller's buffer is not freed).
**Parameters**:
- `sharedMemory` Pointer to the shared memory structure to release.
### TEEC_RequestCancellation
```c
void TEEC_RequestCancellation(TEEC_Operation *operation);
```
Requests cancellation of an in-progress `TEEC_OpenSession` or `TEEC_InvokeCommand` operation. After calling this interface, the corresponding operation may be asynchronously aborted by the TEE.
**Parameters**:
- `operation` Pointer to the target `TEEC_Operation` structure. This must be the same object used by an in-progress `OpenSession` / `InvokeCommand`.
**Notes**:
- This interface is a "request" rather than a "force"; whether the operation is actually aborted depends on the TEE and the target TA.
- The TA needs to call `TEE_GetCancellationFlag` in the GP Internal API to respond to cancellation requests.
## GP TEE Internal API (TEE Side)
The GP TEE Internal Core API is a standard TA development interface defined by GlobalPlatform. **Function signatures, parameter semantics, and return value semantics are authoritative per the official GP specification.** openvela's MiTEE is compatible with these interfaces; however, due to current implementation progress, some interfaces are in an "Incomplete" state.
> **Authoritative References**:
> - [GlobalPlatform TEE Internal Core API Specification v1.3.1](https://globalplatform.org/specs-library/tee-internal-core-api-specification/)
> - `<tee_internal_api.h>` in the `optee_os` source tree
This section provides a **status lookup table** listing openvela's support status for each GP Internal API, helping TA developers determine which APIs can be used directly. For complete signatures, parameters, and return values, refer to the official GP specification above.
**Implementation Status column legend**:
- **Supported** — openvela has fully implemented the function; behavior is consistent with the GP specification
- **Incomplete** — The function symbol exists, but some behavior is not yet implemented or has not been fully validated; not recommended for production use
### TA Lifecycle Entry Points
| Function | Implementation Status | Description |
| ---------------------------- | --------------------- | ------------------------------ |
| `TA_CreateEntryPoint` | Supported | TA creation entry point |
| `TA_DestroyEntryPoint` | Supported | TA destruction entry point |
| `TA_OpenSessionEntryPoint` | Supported | Session open entry point |
| `TA_CloseSessionEntryPoint` | Supported | Session close entry point |
| `TA_InvokeCommandEntryPoint` | Supported | Command invocation entry point |
### Inter-TA Communication
| Function | Implementation Status | Description |
| --------------------- | --------------------- | ------------------------------ |
| `TEE_OpenTASession` | Incomplete | Open an inter-TA session |
| `TEE_CloseTASession` | Incomplete | Close an inter-TA session |
| `TEE_InvokeTACommand` | Incomplete | Invoke a command on another TA |
### Memory Access Check
| Function | Implementation Status | Description |
| ----------------------------- | --------------------- | -------------------------- |
| `TEE_CheckMemoryAccessRights` | Incomplete | Check memory access rights |
### Memory Management
| Function | Implementation Status | Description |
| ---------------- | --------------------- | ----------------- |
| `TEE_Malloc` | Supported | Allocate memory |
| `TEE_Realloc` | Supported | Reallocate memory |
| `TEE_Free` | Supported | Free memory |
| `TEE_MemMove` | Supported | Move memory |
| `TEE_MemCompare` | Supported | Compare memory |
| `TEE_MemFill` | Supported | Fill memory |
### Generic Object Operations
| Function | Implementation Status | Description |
| -------------------- | --------------------- | ---------------------- |
| `TEE_GetObjectInfo1` | Supported | Get object information |
| `TEE_CloseObject` | Supported | Close an object |
### Transient Object Operations
| Function | Implementation Status | Description |
| ----------------------------- | --------------------- | ------------------------------------ |
| `TEE_AllocateTransientObject` | Supported | Allocate a transient object |
| `TEE_FreeTransientObject` | Supported | Free a transient object |
| `TEE_ResetTransientObject` | Supported | Reset a transient object |
| `TEE_PopulateTransientObject` | Supported | Populate transient object attributes |
| `TEE_InitRefAttribute` | Supported | Initialize a reference attribute |
| `TEE_InitValueAttribute` | Supported | Initialize a value attribute |
| `TEE_CopyObjectAttributes1` | Supported | Copy object attributes |
| `TEE_GenerateKey` | Incomplete | Generate a key |
### Persistent Object Operations
| Function | Implementation Status | Description |
| ------------------------------------ | --------------------- | ------------------------------------ |
| `TEE_OpenPersistentObject` | Incomplete | Open a persistent object |
| `TEE_CreatePersistentObject` | Incomplete | Create a persistent object |
| `TEE_CloseAndDeletePersistentObject` | Incomplete | Close and delete a persistent object |
| `TEE_RenamePersistentObject` | Incomplete | Rename a persistent object |
### Persistent Object Data Stream Operations
| Function | Implementation Status | Description |
| ------------------------ | --------------------- | ----------------------- |
| `TEE_ReadObjectData` | Incomplete | Read object data |
| `TEE_WriteObjectData` | Incomplete | Write object data |
| `TEE_TruncateObjectData` | Incomplete | Truncate object data |
| `TEE_SeekObjectData` | Incomplete | Seek object data offset |
### Cryptographic Operation Management
| Function | Implementation Status | Description |
| ------------------------------ | --------------------- | ----------------------------------- |
| `TEE_AllocateOperation` | Supported | Allocate a cryptographic operation |
| `TEE_FreeOperation` | Supported | Free a cryptographic operation |
| `TEE_GetOperationInfo` | Supported | Get operation information |
| `TEE_GetOperationInfoMultiple` | Supported | Get multi-key operation information |
| `TEE_ResetOperation` | Supported | Reset an operation |
| `TEE_SetOperationKey` | Supported | Set operation key |
| `TEE_SetOperationKey2` | Supported | Set dual-key operation |
| `TEE_CopyOperation` | Supported | Copy an operation |
### Message Digest
| Function | Implementation Status | Description |
| ------------------- | --------------------- | --------------------------- |
| `TEE_DigestUpdate` | Supported | Update digest data |
| `TEE_DigestDoFinal` | Supported | Finalize digest computation |
### Symmetric Cipher
| Function | Implementation Status | Description |
| ------------------- | --------------------- | ------------------------------------- |
| `TEE_CipherInit` | Supported | Initialize symmetric cipher operation |
| `TEE_CipherUpdate` | Supported | Update cipher data |
| `TEE_CipherDoFinal` | Supported | Finalize cipher operation |
### MAC (Message Authentication Code)
| Function | Implementation Status | Description |
| --------------------- | --------------------- | ------------------------ |
| `TEE_MACInit` | Supported | Initialize MAC operation |
| `TEE_MACUpdate` | Supported | Update MAC data |
| `TEE_MACComputeFinal` | Supported | Compute final MAC value |
| `TEE_MACCompareFinal` | Supported | Compare final MAC value |
### Authenticated Encryption (AE)
| Function | Implementation Status | Description |
| -------------------- | --------------------- | ------------------------------------ |
| `TEE_AEInit` | Incomplete | Initialize AE operation |
| `TEE_AEUpdateAAD` | Incomplete | Update additional authenticated data |
| `TEE_AEUpdate` | Incomplete | Update AE data |
| `TEE_AEEncryptFinal` | Incomplete | Finalize AE encryption |
| `TEE_AEDecryptFinal` | Incomplete | Finalize AE decryption |
### Asymmetric Cryptography
| Function | Implementation Status | Description |
| ---------------------------- | --------------------- | ----------------------- |
| `TEE_AsymmetricEncrypt` | Incomplete | Asymmetric encryption |
| `TEE_AsymmetricDecrypt` | Incomplete | Asymmetric decryption |
| `TEE_AsymmetricSignDigest` | Incomplete | Asymmetric signature |
| `TEE_AsymmetricVerifyDigest` | Incomplete | Asymmetric verification |
### Key Derivation
| Function | Implementation Status | Description |
| --------------- | --------------------- | ------------ |
| `TEE_DeriveKey` | Incomplete | Derive a key |
### Random Number Generation
| Function | Implementation Status | Description |
| -------------------- | --------------------- | -------------------- |
| `TEE_GenerateRandom` | Incomplete | Generate random data |
### Time API
| Function | Implementation Status | Description |
| ------------------------- | --------------------- | ---------------------- |
| `TEE_GetSystemTime` | Incomplete | Get system time |
| `TEE_GetTAPersistentTime` | Incomplete | Get TA persistent time |
| `TEE_SetTAPersistentTime` | Incomplete | Set TA persistent time |
| `TEE_GetREETime` | Incomplete | Get REE time |

View File

@ -1,165 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/services/ams.md) \]
# AMS API
Activity Manager Service (AMS) is the activity management service module in the openvela XMS system, responsible for managing application lifecycles and scheduling tasks and activities.
## Features
- **Activity Lifecycle Management**: AMS manages the lifecycle of Activities within applications, including creation, starting, pausing, resuming, and destruction.
- **Task Management**: AMS manages application tasks and task stacks, including task switching and scheduling, ensuring a smooth user experience.
- **Process Management**: AMS is responsible for starting, stopping, and monitoring application processes, ensuring effective utilization of system resources.
- **Intent Handling**: AMS handles Intent communication between applications, allowing different applications to start Activities and Services.
- **Permission Management**: AMS participates in permission checks, ensuring applications meet system security requirements when starting Activities.
- **Application State Tracking**: AMS tracks application states (such as foreground, background, stopped) and allocates resources accordingly.
- **Multi-Window Support**: AMS provides Activity management in multi-window mode, allowing multiple applications to be displayed simultaneously.
- **Background Task Restrictions**: AMS imposes restrictions on background tasks and services to optimize system performance and battery usage.
- **Service and Broadcast Management**: AMS also manages the lifecycle of Services and BroadcastReceivers, ensuring system responsiveness and stability.
## Examples
The following example code demonstrates how to use the openvela AMS module, typically through the `ActivityManager` class to manage Activities and control tasks.
**Start a New Activity**
```cpp
Intent intent;
makeIntent(intent);
intent.setFlag(intent.mFlag | Intent::FLAG_ACTIVITY_NEW_TASK);
android::sp<android::IBinder> token = new android::BBinder();
ActivityManager am;
am.startActivity(token, intent, -1);
```
**Stop an Activity**
```cpp
Intent intent;
makeIntent(intent);
ActivityManager am;
am.stopActivity(intent, intent.mFlag);
```
## Core Classes
### ActivityManager
Header: `#include <app/ActivityManager.h>`
Facade class for accessing AMS capabilities on the client side. Main methods provided:
- `startActivity()` / `stopActivity()` / `finishActivity()` — Activity start/stop
- `startService()` / `stopService()` / `stopServiceByToken()` / `bindService()` / `unbindService()` — Service operations
- `publishService()` / `getService()` — Service publishing and retrieval
- `sendBroadcast()` / `registerReceiver()` / `unregisterReceiver()` — Broadcast and receivers
- `attachApplication()` / `stopApplication()` — Application binding and termination
- `moveActivityTaskToBackground()` — Move Activity task to background
- `reportActivityStatus()` / `reportServiceStatus()` — Status reporting (application reports lifecycle status to AMS)
- `postIntent()` — Deliver Intent to a specified component
### ActivityManagerService
Header: `#include <am/ActivityManagerService.h>`
Server-side implementation class of AMS, registered as a system service, receiving calls from applications via Binder and performing scheduling. Developers generally do not use this class directly.
### Activity
Header: `#include <app/Activity.h>`
Base class for UI units in application development. Applications implement a screen by inheriting this class and overriding lifecycle callbacks such as `onCreate` / `onStart` / `onResume` / `onPause` / `onStop` / `onDestroy` / `onRestart`. Also provides operations and extension points such as `finish` / `setResult` / `getWindow` / `moveToBackground` / `onBackPressed` / `onActivityResult` / `onNewIntent`.
### Application
Header: `#include <app/Application.h>`
Global singleton base class for the application process. Applications typically inherit `Application` to hold process-level resources. Main methods include:
- Lifecycle: `onCreate` / `onDestroy` / `onForeground` / `onBackground` / `onReceiveIntent`
- Component management: `createActivity` / `createService` / `addActivity` / `addService` / `findActivity` / `findService` / `deleteActivity` / `deleteService`
- Metadata: `getPackageName` / `getUid` / `isSystemUI` / `getMainLoop` / `getWindowManager`
### ApplicationThread
Header: `#include <app/ApplicationThread.h>`
Scheduling thread abstraction on the Application side, receiving scheduling requests from AMS and dispatching execution within the application process. This is an internal framework collaboration class; application developers generally do not call it directly.
### AppMain
Header: `#include <app/AppMain.h>`
Application process entry helper class. Defines the basic flow from process startup to connecting with AMS, encapsulating the main event loop and initialization steps.
### Context
Header: `#include <app/Context.h>`
The most fundamental context base class, providing access to system capabilities. Typical methods include:
- `getPackageName()` / `getApplication()` / `getComponentName()` — Application and component information
- `startActivity()` / `startActivityForResult()` / `stopActivity()` — Activity start/stop
- `startService()` / `stopService()` / `bindService()` / `unbindService()` — Service operations
- `sendBroadcast()` / `registerReceiver()` / `unregisterReceiver()` — Broadcast and receivers
- `getActivityManager()` / `getWindowManager()` — System service access
- `getMainLoop()` / `getCurrentLoop()` — Event loop retrieval
### ContextImpl
Header: `#include <app/ContextImpl.h>`
Default implementation of the `Context` base class, assembled by the framework when creating Application / Activity / Service instances. Application developers typically do not construct `ContextImpl` directly, but obtain instances through methods like `Activity::getContext()`.
### Intent
Header: `#include <app/Intent.h>`
Data structure carrying communication intent between components. Contains fields such as action, data, target, bundle, flag, and launch flags like `FLAG_ACTIVITY_*`. Provides read/write methods including `setAction` / `setData` / `setTarget` / `setBundle` / `setFlag` / `readFromParcel` / `writeToParcel`.
### Service
Header: `#include <app/Service.h>`
Base class for long-lived components without a UI. Developers implement background services by inheriting `Service` and overriding `onCreate` / `onStartCommand` / `onBind` / `onUnbind` / `onDestroy` / `onReceiveIntent`.
### ServiceConnection
Header: `#include <app/ServiceConnection.h>`
Connection callback interface for `bindService`. Contains two callback methods `onServiceConnected` / `onServiceDisconnected`, used to notify the client when binding succeeds or disconnects.
### BroadcastReceiver
Header: `#include <app/BroadcastReceiver.h>`
Base class for broadcast receivers. Applications handle matched system or application broadcasts by inheriting this class and overriding `onReceive(Intent)`.
### MessageService
Header: `#include <app/MessageService.h>`
Service helper class for message-based communication, encapsulating the request-response pattern based on Intent, facilitating the construction of message-dispatching background services. Main methods: `sendMessage` / `receiveMessage` / `receiveMessageAndReply` / `reply` / `onBind` / `onBindExt` / `onReply`.
### Dialog
Header: `#include <app/Dialog.h>`
Base class for dialog components. Provides operations such as `show` / `hide` / `setLayout` / `setRect` / `getLayout` / `getRoot` / `createDialog`; applications can inherit to implement custom dialogs.
### UvLoop
Header: `#include <app/UvLoop.h>`
Event loop wrapper based on libuv, reused by the application main thread and other framework components. Provides capabilities such as timers, IO events, and work queues.
### Logger
Header: `#include <app/Logger.h>`
Common logging macro definitions for AMS/application side, encapsulating leveled log output (`APP_LOGI` / `APP_LOGW` / `APP_LOGE`, etc.).
### ActivityTrace
Header: `#include <ActivityTrace.h>`
Collection of trace instrumentation macros for Activity lifecycle, enabling visualization of application startup and switching paths with openvela trace analysis tools.

View File

@ -1,8 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/services/index.md) \]
# Services API
The Services module provides core application management services for the openvela system, including Activity Manager Service (AMS) and Package Manager Service (PMS), responsible for application lifecycle management, task scheduling, and package management.
- **[AMS](ams.md)** — Activity Manager Service, application/Activity lifecycle management
- **[PMS](pms.md)** — Package Manager Service, application package management

View File

@ -1,107 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/services/pms.md) \]
# PMS API
Package Manager Service (PMS) is the package management module in the openvela XMS system.
## Features
- Package installation
- Package information query
- Package uninstallation
## Examples
**Package management via command line**
Install a package:
```
pm install [packagename]
```
List installed packages:
```
pm list
```
**Package management via source code**
Install a package:
```cpp
#include <pm/PackageManager.h>
PackageManager pm;
InstallParam parms;
pm.installPackage(parms);
```
Get all package information:
```cpp
#include <pm/PackageManager.h>
PackageManager pm;
std::vector<PackageInfo> pgInfos;
pm.getAllPackageInfo(&pgInfos);
```
Uninstall a package:
```cpp
#include <pm/PackageManager.h>
PackageManager pm;
UninstallParam parms;
pm.uninstallPackage(parms);
```
## Core Classes
### PackageManager
Header: `#include <pm/PackageManager.h>`
The facade class for accessing PMS capabilities on the client side. Main operations:
- `installPackage(InstallParam)` — Install an application package
- `uninstallPackage(UninstallParam)` — Uninstall an application package
- `getAllPackageInfo(std::vector<PackageInfo>*)` — Query all installed package information
- `getPackageInfo(packageName, PackageInfo*)` — Query information for a specific package
- `getAllPackageName(std::vector<std::string>*)` — Query all installed package names
- `getPackageSizeInfo(packageName, ...)` — Query package storage usage
- `clearAppCache(packageName)` — Clear application cache
- `isFirstBoot()` — Query whether this is the first boot
Applications typically construct a `PackageManager` instance and call the above methods directly. Internally it communicates with `PackageManagerService` via Binder.
### PackageManagerService
Header: `#include <pm/PackageManagerService.h>`
The server-side implementation class of PMS, registered as a system service. It maintains installed package metadata, performs actual install/uninstall operations, and handles permission and signature verification. Developers generally do not use this class directly.
### PackageInfo
Header: `#include <pm/PackageInfo.h>`
A structure describing the metadata of a single installed package. Main fields include:
- `packageName` / `name` — Package name and application name
- `version` / `priority` / `appType` — Version, priority, and application type
- `installedPath` / `installTime` / `size` — Installation path, installation time, and storage size
- `execfile` / `entry` / `manifest` — Executable file, entry point, and manifest
- `activitiesInfo` / `servicesInfo` — Internal Activity and Service lists
- `shasum` — Signature digest
- `userId` / `isSystemUI` — User ID and whether it is a system UI
- `windowEnterAnim` / `windowExitAnim` — Window enter/exit animation configuration
Query interfaces of `PackageManager` return results of this type.
### PackageTrace
Header: `#include <PackageTrace.h>`
A collection of trace macros for PMS, used to trace package management operation paths. Works with openvela trace tools for performance analysis.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,113 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/index.md) \]
# Telephony API
Telephony provides cellular communication capabilities. `framework/telephony` is the interface layer that openvela exposes to the application layer for cellular communication, also known as TAPI (Telephony API). The encapsulated interfaces cover cellular communication services: network services, calls, SMS, data, SIM dual-card, and modem configuration management.
TAPI is independent of the openvela telephony core stack. Its internal logic uses DBUS LIB to encapsulate the business logic of the Core Stack, shielding the complexity of D-Bus operations. It provides standardized and unified Telephony API interface definitions in standard C, making it convenient for openvela application layer APPs to use and enabling reuse across openvela system versions.
## openvela Implementation Notes
- **Architecture**: TAPI encapsulates the Telephony Core Stack (oFono) via D-Bus, exposing standard C interfaces externally
- **SIM identification**: Different SIM slots are distinguished via the `slot_id` parameter
- **Asynchronous model**: Most operations return results asynchronously through callback functions
## Module Overview
| Module | Source | API Documentation | Description |
| :--- | :--- | :--- | :--- |
| Unified header file | `tapi.h` | [Common Utilities](telephony.md) | Common type definitions, string/enum conversion utils |
| Radio interface | `tapi_manager.c/h` | [Manager](telephony_manager.md) | Telephony initialization, status query, event registration |
| Call interface | `tapi_call.c/h` | [Call](telephony_call.md) | Voice call control |
| Supplementary Services | `tapi_ss.c/h` | [Supplementary Services (SS)](telephony_ss.md) | Call forwarding/barring/waiting/CLIR/USSD |
| Simplified Phone Service | `tapi_phone.c/h` | [Simplified Phone Service](telephony_phone.md) | Lightweight client wrapper |
| Network interface | `tapi_network.c/h` | [Network](telephony_network.md) | Network registration, signal, operator |
| Data interface | `tapi_data.c/h` | [Data](telephony_data.md) | Cellular data connection |
| SIM interface | `tapi_sim.c/h` | [SIM Card](telephony_sim.md) | SIM card management |
| SIM Toolkit | `tapi_stk.c/h` | [SIM Toolkit](telephony_stk.md) | STK Agent and SIM proactive commands |
| Phonebook | `tapi_phonebook.c/h` | [Phonebook](telephony_phonebook.md) | ADN/FDN phonebook management |
| SMS interface | `tapi_sms.c/h` | [SMS](telephony_sms.md) | SMS message sending and receiving |
| Cell Broadcast | `tapi_cbs.c/h` | [Cell Broadcast (CBS)](telephony_cbs.md) | Cell broadcast messages |
| IMS interface | `tapi_ims.c/h` | [IMS](telephony_ims.md) | VoLTE/VoWiFi |
## TAPI Configuration
A complete Telephony service involves many modules. All modules need to be enabled for full Telephony functionality.
**DBUS Configuration**
```kconfig
CONFIG_DBUS_DAEMON=y
CONFIG_DBUS_MONITOR=y
CONFIG_DBUS_SEND=y
CONFIG_LIB_DBUS=y
```
**GLIB Configuration**
```kconfig
CONFIG_LIB_GLIB=y
```
**OFONO Configuration**
```kconfig
CONFIG_LIB_ELL=y
CONFIG_OFONO=y
CONFIG_OFONO_RILMODEM=y # modem type selection, choose rilmodem for rild support
CONFIG_OFONO_ATMODEM=y # choose atmodem for serial/USB support
```
**GDBUS Configuration**
```kconfig
CONFIG_LIB_DBUS=y
```
**Telephony API Configuration**
```kconfig
CONFIG_TELEPHONY=y
CONFIG_TELEPHONY_TOOL=y # debug tool, optional
```
## TAPI Working Model
![TAPIWork](figures/TapiWork.png)
## TAPI Usage Examples
### Obtaining the TAPI Working Context
First declare a callback function:
```c
static void on_tapi_client_ready(const char* client_name, void* user_data)
{
if (client_name != NULL)
syslog(LOG_DEBUG, "tapi is ready for %s\n", client_name);
...
}
```
Then call `tapi_open` to obtain the context. Successful acquisition requires oFono, D-Bus, and other services to be started successfully. The callback function is invoked when ready.
```c
tapi_context context;
char* dbus_name = "vela.telephony.tool";
context = tapi_open(dbus_name, on_tapi_client_ready, NULL);
```
### Releasing the TAPI Working Context
```c
tapi_close(context);
```
### Querying the Current Radio Power State
```c
int slot_id = 0;
bool value = false;
tapi_get_radio_power(context, slot_id, &value);
```

View File

@ -1,362 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony.md) \]
# Telephony Common Utilities API
General-purpose utility functions provided by TAPI, covering status string conversion, modem path resolution, operator status parsing, and other helper capabilities.
Header: `#include <tapi.h>`
## openvela Implementation Notes
- **String/enum conversion**: The `*_from_string` / `*_to_string` series convert between oFono D-Bus strings and TAPI enumerations for status parsing
- **Modem path**: `tapi_utils_get_modem_path` converts a `slot_id` to an oFono modem object path
- **Utility nature**: These interfaces do not depend on tapi_context and can be called directly from anywhere
- **Use cases**: Implementing custom event handling, printing debug logs, or extending TAPI capabilities
## SIM State
### tapi_sim_state_to_string
```c
const char* tapi_sim_state_to_string(tapi_sim_state state);
```
Convert a SIM state enumeration to a human-readable string.
**Parameters**:
- `state` SIM state enumeration value.
**Returns**:
Returns the string representation of the state, or `NULL` / a placeholder string on failure.
## APN Utilities
### tapi_utils_apn_auth_from_string
```c
int tapi_utils_apn_auth_from_string(const char* str);
```
Convert an authentication type string to an APN authentication enumeration value.
**Parameters**:
- `str` Authentication type string (e.g., `"pap"`, `"chap"`).
**Returns**:
Returns the authentication enumeration value; returns an error value for invalid strings.
### tapi_utils_apn_auth_to_string
```c
const char* tapi_utils_apn_auth_to_string(int auth);
```
Convert an APN authentication enumeration value to a string.
**Parameters**:
- `auth` Authentication enumeration value.
**Returns**:
Returns the corresponding string.
### tapi_utils_apn_proto_from_string
```c
int tapi_utils_apn_proto_from_string(const char* str);
```
Convert a protocol string to an APN protocol enumeration value.
**Parameters**:
- `str` Protocol string (e.g., `"ip"`, `"ipv6"`, `"dual"`).
**Returns**:
Returns the protocol enumeration value.
### tapi_utils_apn_proto_to_string
```c
const char* tapi_utils_apn_proto_to_string(int proto);
```
Convert an APN protocol enumeration value to a string.
**Parameters**:
- `proto` Protocol enumeration value.
**Returns**:
Returns the corresponding string.
### tapi_utils_apn_type_from_string
```c
int tapi_utils_apn_type_from_string(const char* str);
```
Convert an APN type string to a type enumeration value.
**Parameters**:
- `str` APN type string (e.g., `"default"`, `"mms"`, `"ims"`).
**Returns**:
Returns the type enumeration value.
### tapi_utils_apn_type_to_string
```c
const char* tapi_utils_apn_type_to_string(int type);
```
Convert an APN type enumeration value to a string.
**Parameters**:
- `type` APN type enumeration value.
**Returns**:
Returns the corresponding string.
## Call Utilities
### tapi_utils_call_disconnected_reason
```c
int tapi_utils_call_disconnected_reason(const char* reason);
```
Convert a call disconnection reason string to a TAPI disconnection reason enumeration value.
**Parameters**:
- `reason` Disconnection reason string.
**Returns**:
Returns the disconnection reason enumeration value.
### tapi_utils_call_status_from_string
```c
int tapi_utils_call_status_from_string(const char* status);
```
Convert a call status string to a status enumeration value.
**Parameters**:
- `status` Status string (e.g., `"active"`, `"held"`, `"dialing"`).
**Returns**:
Returns the status enumeration value.
## Cell and Network Utilities
### tapi_utils_cell_type_from_string
```c
int tapi_utils_cell_type_from_string(const char* str);
```
Convert a cell type string to an enumeration value.
**Parameters**:
- `str` Cell type string.
**Returns**:
Returns the cell type enumeration value.
### tapi_utils_cell_type_to_string
```c
const char* tapi_utils_cell_type_to_string(int type);
```
Convert a cell type enumeration value to a string.
**Parameters**:
- `type` Cell type enumeration value.
**Returns**:
Returns the corresponding string.
### tapi_utils_network_mode_from_string
```c
int tapi_utils_network_mode_from_string(const char* str);
```
Convert a network mode string to an enumeration value.
**Parameters**:
- `str` Network mode string (e.g., `"gsm"`, `"lte"`).
**Returns**:
Returns the network mode enumeration value.
### tapi_utils_network_mode_to_string
```c
const char* tapi_utils_network_mode_to_string(int mode);
```
Convert a network mode enumeration value to a string.
**Parameters**:
- `mode` Network mode enumeration value.
**Returns**:
Returns the corresponding string.
### tapi_utils_network_type_from_ril_tech
```c
int tapi_utils_network_type_from_ril_tech(int tech);
```
Convert a RIL layer network technology value to a TAPI network type enumeration.
**Parameters**:
- `tech` RIL network technology value.
**Returns**:
Returns the TAPI network type enumeration value.
### tapi_utils_network_operator_status_from_string
```c
int tapi_utils_network_operator_status_from_string(const char* str);
```
Convert an operator status string to an enumeration value.
**Parameters**:
- `str` Operator status string.
**Returns**:
Returns the operator status enumeration value.
### tapi_utils_operator_status_from_string
```c
int tapi_utils_operator_status_from_string(const char* str);
```
Shorthand version of `tapi_utils_network_operator_status_from_string` with equivalent functionality.
**Parameters**:
- `str` Operator status string.
**Returns**:
Returns the operator status enumeration value.
## Registration State Utilities
### tapi_utils_registration_mode_from_string
```c
int tapi_utils_registration_mode_from_string(const char* str);
```
Convert a registration mode string to an enumeration value.
**Parameters**:
- `str` Registration mode string (e.g., `"auto"`, `"manual"`).
**Returns**:
Returns the registration mode enumeration value.
### tapi_utils_registration_status_from_string
```c
int tapi_utils_registration_status_from_string(const char* str);
```
Convert a registration status string to an enumeration value.
**Parameters**:
- `str` Registration status string.
**Returns**:
Returns the registration status enumeration value.
### tapi_utils_get_registration_status_string
```c
const char* tapi_utils_get_registration_status_string(int status);
```
Convert a registration status enumeration value to a human-readable string.
**Parameters**:
- `status` Registration status enumeration value.
**Returns**:
Returns the corresponding string.
## Modem Path and Slot
### tapi_utils_get_modem_path
```c
const char* tapi_utils_get_modem_path(int slot_id);
```
Get the oFono modem object path for a given SIM slot ID.
**Parameters**:
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns the modem object path string (e.g., `/ril_0`, `/ril_1`).
### tapi_utils_get_slot_id
```c
int tapi_utils_get_slot_id(const char* path);
```
Parse the SIM slot ID from an oFono modem object path.
**Parameters**:
- `path` Modem object path.
**Returns**:
Returns the corresponding slot ID (0 or 1), or a negative value for invalid paths.

View File

@ -1,694 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_call.md) \]
# Call Management API
Voice call control, including dialing, answering, hanging up, holding, and more.
Header: `#include <tapi_call.h>`
## openvela Implementation Notes
- **SIM identification**: Some interfaces do not take a `slot_id` and use the default slot; use `tapi_call_set_default_slot` to switch when a specific slot is needed
- **Synchronous/Asynchronous**: Time-consuming operations such as dialing and answering provide both synchronous versions and `_async` versions (callback-style)
- **Operate by ID**: Long-lived calls are uniquely identified by the call ID (string) returned; `*_by_id` interfaces operate on the call accordingly
- **DTMF**: Keypad tones are triggered via `tapi_call_send_tones` (batch) or `tapi_call_start_dtmf` / `tapi_call_stop_dtmf` (continuous key press)
- **Conference calls**: Organized via `tapi_call_dial_conferece` and `tapi_call_merge_call`, and split via `tapi_call_separate_call`
## Dialing and Answering
### tapi_call_dial
```c
int tapi_call_dial(tapi_context context, int slot_id, char* number, int hide_callerid, int event_id, tapi_async_function p_handle);
```
Initiate a voice call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `number` Phone number.
- `hide_callerid` Whether to hide the caller ID.
- `event_id` Event ID, used for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_dial_async
```c
int tapi_call_dial_async(tapi_context context, int slot_id, char* number, int hide_callerid, int event_id, void* user_data, tapi_async_function p_handle);
```
Initiate a voice call (asynchronous version).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `number` Phone number.
- `hide_callerid` Whether to hide the caller ID.
- `event_id` Event ID, used for callback matching.
- `user_data` User data passed to the callback function.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Hangup Control
### tapi_call_hangup_all_calls
```c
int tapi_call_hangup_all_calls(tapi_context context, int slot_id);
```
Hang up all calls.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Hold and Swap
### tapi_call_release_and_answer
```c
int tapi_call_release_and_answer(tapi_context context, int slot_id);
```
Release the current call and answer the waiting incoming call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_hold_and_answer
```c
int tapi_call_hold_and_answer(tapi_context context, int slot_id);
```
Hold the current call and answer the waiting incoming call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_release_and_swap
```c
int tapi_call_release_and_swap(tapi_context context, int slot_id);
```
Release the current call and swap to the held call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_hold_call
```c
int tapi_call_hold_call(tapi_context context, int slot_id);
```
Hold the current call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_unhold_call
```c
int tapi_call_unhold_call(tapi_context context, int slot_id);
```
Resume the held call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Transfer and Conference
### tapi_call_transfer
```c
int tapi_call_transfer(tapi_context context, int slot_id);
```
Transfer the call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_merge_call
```c
int tapi_call_merge_call(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Merge calls (multi-party call).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID, used for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_merge_call_async
```c
int tapi_call_merge_call_async(tapi_context context, int slot_id, int event_id, void* user_data, tapi_async_function p_handle);
```
Merge calls (multi-party call) (asynchronous version).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID, used for callback matching.
- `user_data` User data passed to the callback function.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_separate_call
```c
int tapi_call_separate_call(tapi_context context, int slot_id, int event_id, char* call_id, tapi_async_function p_handle);
```
Separate a specified call from a multi-party call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID, used for callback matching.
- `call_id` Call ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_hangup_multiparty
```c
int tapi_call_hangup_multiparty(tapi_context context, int slot_id);
```
Hang up a conference call session.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## DTMF and Dial Tones
### tapi_call_send_tones
```c
int tapi_call_send_tones(void* context, int slot_id, char* tones);
```
Send a DTMF tone playing request.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `tones` DTMF tone sequence.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Call Queries
### tapi_call_get_all_calls
```c
int tapi_call_get_all_calls(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get all current calls.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID, used for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_get_call_by_state
```c
int tapi_call_get_call_by_state(tapi_context context, int slot_id, int state, tapi_call_info* call_list, int size, tapi_call_info* out_list);
```
Filter calls by the given call state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `state` State.
- `call_list` Call list.
- `size` Size.
- `out_list` Output list.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Emergency Numbers
### tapi_call_get_ecc_list
```c
int tapi_call_get_ecc_list(tapi_context context, int slot_id, ecc_info* out);
```
Get the emergency call number list.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_is_emergency_number
```c
int tapi_call_is_emergency_number(tapi_context context, char* number);
```
Check whether the given number is an emergency number.
**Parameters**:
- `context` Telephony context handle.
- `number` Phone number.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Event Subscription
### tapi_call_register_emergency_list_change
```c
int tapi_call_register_emergency_list_change(tapi_context context, int slot_id, void* user_obj, tapi_async_function p_handle);
```
Register a callback for emergency number list changes.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_register_ringback_tone_change
```c
int tapi_call_register_ringback_tone_change(tapi_context context, int slot_id, void* user_obj, tapi_async_function p_handle);
```
Register a callback for ringback tone changes.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_register_default_voicecall_slot_change
```c
int tapi_call_register_default_voicecall_slot_change(tapi_context context, void* user_obj, tapi_async_function p_handle);
```
Register a callback for default voice call slot changes.
**Parameters**:
- `context` Telephony context handle.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Conference Calls
### tapi_call_dial_conferece
```c
int tapi_call_dial_conferece(tapi_context context, int slot_id, char* participants[], int size);
```
Initiate an IMS conference call.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `participants` Participant list.
- `size` Size.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_invite_participants
```c
int tapi_call_invite_participants(tapi_context context, int slot_id, char* participants[], int size);
```
Request the conference server to invite additional participants to the conference.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `participants` Participant list.
- `size` Size.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_register_call_state_change
```c
int tapi_call_register_call_state_change(tapi_context context, int slot_id, void* user_obj, tapi_async_function p_handle);
```
Register a callback for call state changes.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Operate by ID
### tapi_call_answer_by_id
```c
int tapi_call_answer_by_id(tapi_context context, int slot_id, char* call_id);
```
Answer a call by its ID.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `call_id` Call ID.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_answer_by_id_async
```c
int tapi_call_answer_by_id_async(tapi_context context, int slot_id, char* call_id, void* user_obj, tapi_async_function p_handle);
```
Answer a call by its ID (asynchronous version; the result is returned via callback).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `call_id` Call ID.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_hangup_by_id
```c
int tapi_call_hangup_by_id(tapi_context context, int slot_id, char* call_id);
```
Hang up a call by its ID.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `call_id` Call ID.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_deflect_by_id
```c
int tapi_call_deflect_by_id(tapi_context context, int slot_id, char* call_id, char* number);
```
Deflect an incoming call to the specified number.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `call_id` Call ID.
- `number` Phone number.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Continuous DTMF
### tapi_call_start_dtmf
```c
int tapi_call_start_dtmf(tapi_context context, int slot_id, unsigned char digit, int event_id, tapi_async_function p_handle);
```
Start sending a DTMF tone.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `digit` DTMF key character.
- `event_id` Event ID, used for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_stop_dtmf
```c
int tapi_call_stop_dtmf(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Stop sending a DTMF tone.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID, used for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Default Slot
### tapi_call_set_default_slot
```c
int tapi_call_set_default_slot(tapi_context context, int slot_id);
```
Set the default voice call slot.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_call_get_default_slot
```c
int tapi_call_get_default_slot(tapi_context context, int* out);
```
Get the default voice call slot.
**Parameters**:
- `context` Telephony context handle.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,114 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_cbs.md) \]
# Telephony Cell Broadcast API
Cell Broadcast Service (CBS) provides cell broadcast capabilities over cellular networks, commonly used for receiving government emergency alerts (earthquakes, tsunamis) and carrier announcements.
Header: `#include <tapi_cbs.h>`
## openvela Implementation Notes
- **Power control**: Enable/disable cell broadcast reception via `set_cell_broadcast_power_on`
- **Topic subscription**: Configure broadcast topic ranges (by channel ID) via `set_cell_broadcast_topics`
- **Event callback**: Register event callbacks via `tapi_cbs_register` to receive broadcast messages
- **SIM identification**: All interfaces include a `slot_id` parameter for multi-SIM devices
- **Related protocol**: Corresponds to the Cell Broadcast procedure defined in 3GPP TS 23.041
## Power Control
### tapi_sms_set_cell_broadcast_power_on
```c
int tapi_sms_set_cell_broadcast_power_on(tapi_context context, int slot_id, bool enabled);
```
Enable or disable cell broadcast reception.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `enabled` `true` to enable, `false` to disable.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_sms_get_cell_broadcast_power_on
```c
int tapi_sms_get_cell_broadcast_power_on(tapi_context context, int slot_id, bool* enabled);
```
Query the cell broadcast reception power state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `enabled` Output parameter, returns the current power state.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Topic Subscription
### tapi_sms_set_cell_broadcast_topics
```c
int tapi_sms_set_cell_broadcast_topics(tapi_context context, int slot_id, char* topics);
```
Configure the cell broadcast topic range (channel ID list).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `topics` Topic string, typically comma-separated channel IDs or ranges (e.g., `"4352-4356,919"`).
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_sms_get_cell_broadcast_topics
```c
int tapi_sms_get_cell_broadcast_topics(tapi_context context, int slot_id, char** topics);
```
Query the currently configured cell broadcast topics.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `topics` Output parameter, returns the topic string (caller is responsible for freeing).
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Event Subscription
### tapi_cbs_register
```c
int tapi_cbs_register(tapi_context context, int slot_id, tapi_indication_msg msg,
void* user_obj, tapi_async_function p_handle);
```
Register a cell broadcast event callback.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `msg` Event type to listen for.
- `user_obj` User data, passed back to the callback function.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns the event subscription watch ID on success, or a negative error code on failure.

View File

@ -1,495 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_data.md) \]
# Data Connection API
Cellular data connection management.
Header file: `#include <tapi_data.h>`
## openvela Implementation Notes
- **APN context**: Manage APN configurations (add/remove/edit/query) via the `tapi_data_*_apn_context` series of interfaces
- **On-demand connection**: `tapi_data_request_network` / `tapi_data_release_network` controls data network establishment and release
- **Roaming control**: Explicitly toggle data roaming via `tapi_data_enable_roaming`
- **SIM identification**: Operations involving a specific SIM use the `slot_id` parameter; the default data SIM is set via `tapi_data_set_default_slot`
- **State subscription**: `tapi_data_register` / `tapi_data_unregister` for registering/unregistering state change events
## APN Configuration Management
### tapi_data_load_apn_contexts
```c
int tapi_data_load_apn_contexts(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Load APN configurations.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_add_apn_context
```c
int tapi_data_add_apn_context(tapi_context context, int slot_id, int event_id, tapi_data_context* apn, tapi_async_function p_handle);
```
Add an APN configuration.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `apn` Access Point Name (APN) configuration.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_remove_apn_context
```c
int tapi_data_remove_apn_context(tapi_context context, int slot_id, int event_id, tapi_data_context* apn, tapi_async_function p_handle);
```
Remove an APN configuration.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `apn` Access Point Name (APN) configuration.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_edit_apn_context
```c
int tapi_data_edit_apn_context(tapi_context context, int slot_id, int event_id, tapi_data_context* apn, tapi_async_function p_handle);
```
Edit an APN configuration.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `apn` Access Point Name (APN) configuration.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_reset_apn_contexts
```c
int tapi_data_reset_apn_contexts(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Reset APN configurations to defaults.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Data Network Status
### tapi_data_is_registered
```c
int tapi_data_is_registered(tapi_context context, int slot_id, bool* out);
```
Query whether the data network is registered.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_is_data_emergency_only
```c
int tapi_data_is_data_emergency_only(tapi_context context, int slot_id, bool* out);
```
Query whether the data connection is emergency-only.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_get_network_type
```c
int tapi_data_get_network_type(tapi_context context, int slot_id, tapi_network_type* out);
```
Get the current network type.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_is_data_roaming
```c
int tapi_data_is_data_roaming(tapi_context context, int slot_id, bool* out);
```
Query whether data roaming is active.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Data Connection Control
### tapi_data_request_network
```c
int tapi_data_request_network(tapi_context context, int slot_id, const char* type);
```
Request to establish a data connection.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `type` Type.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_release_network
```c
int tapi_data_release_network(tapi_context context, int slot_id, const char* type);
```
Release a data connection.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `type` Type.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_get_data_connection_list
```c
int tapi_data_get_data_connection_list(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get the data connection list.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Preferred APN
### tapi_data_set_preferred_apn
```c
int tapi_data_set_preferred_apn(tapi_context context, int slot_id, tapi_data_context* apn);
```
Set the preferred APN.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `apn` Access Point Name (APN) configuration.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_get_preferred_apn
```c
int tapi_data_get_preferred_apn(tapi_context context, int slot_id, char** out);
```
Get the preferred APN.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Data Switch
### tapi_data_enable_data
```c
int tapi_data_enable_data(tapi_context context, bool enabled);
```
Enable or disable cellular data.
**Parameters**:
- `context` Telephony context handle.
- `enabled` Whether to enable.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_get_enabled
```c
int tapi_data_get_enabled(tapi_context context, bool* out);
```
Query whether cellular data is enabled.
**Parameters**:
- `context` Telephony context handle.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Roaming Control
### tapi_data_enable_roaming
```c
int tapi_data_enable_roaming(tapi_context context, bool enabled);
```
Enable or disable data roaming.
**Parameters**:
- `context` Telephony context handle.
- `enabled` Whether to enable.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_get_roaming_enabled
```c
int tapi_data_get_roaming_enabled(tapi_context context, bool* out);
```
Query whether data roaming is enabled.
**Parameters**:
- `context` Telephony context handle.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Default Slot and Authorization
### tapi_data_set_default_slot
```c
int tapi_data_set_default_slot(tapi_context context, int slot_id);
```
Set the default data SIM card slot.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_get_default_slot
```c
int tapi_data_get_default_slot(tapi_context context, int* out);
```
Get the default data SIM card slot.
**Parameters**:
- `context` Telephony context handle.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_set_data_allow
```c
int tapi_data_set_data_allow(tapi_context context, int slot_id, int event_id, bool allowed, tapi_async_function p_handle);
```
Set data permission for the specified slot.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `allowed` Whether to allow.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Event Subscription
### tapi_data_register
```c
int tapi_data_register(tapi_context context, int slot_id, tapi_indication_msg msg, void* user_obj, tapi_async_function p_handle);
```
Register a data state change event callback.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `msg` Message content.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_data_unregister
```c
int tapi_data_unregister(tapi_context context, int watch_id);
```
Unregister a data state change event callback.
**Parameters**:
- `context` Telephony context handle.
- `watch_id` Watch ID (used to cancel the subscription).
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,200 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_ims.md) \]
# IMS Service API
IP Multimedia Subsystem (VoLTE/VoWiFi) management.
Header: `#include <tapi_ims.h>`
## openvela Implementation Notes
- **IMS Switch**: Controls IMS service enable/disable state via `turn_on` / `turn_off`
- **Registration Status**: Queries whether IMS is registered to the network, subscribes to registration state change events
- **Service Switch**: `set_service_status` controls enabling of specific services (e.g. voice, video)
- **VoLTE Support**: Queries whether the current network supports VoLTE via `is_volte_available`
- **SIM identification**: All interfaces include a `slot_id` parameter
## IMS Switch
### tapi_ims_turn_on
```c
int tapi_ims_turn_on(tapi_context context, int slot_id);
```
Enables IMS service (VoLTE/VoWiFi).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_ims_turn_off
```c
int tapi_ims_turn_off(tapi_context context, int slot_id);
```
Disables IMS service.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Service Status Configuration
### tapi_ims_set_service_status
```c
int tapi_ims_set_service_status(tapi_context context, int slot_id, int capability);
```
Sets IMS service status (VoLTE/VoWiFi).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `capability` Capability value.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Registration Status and Events
### tapi_ims_get_registration
```c
int tapi_ims_get_registration(tapi_context context, int slot_id, tapi_ims_registration_info* ims_reg);
```
Gets IMS registration information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `ims_reg` IMS registration status.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_ims_register_registration_change
```c
int tapi_ims_register_registration_change(tapi_context context, int slot_id, void* user_obj, tapi_async_function p_handle);
```
Registers a callback for IMS registration state changes.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_ims_is_registered
```c
int tapi_ims_is_registered(tapi_context context, int slot_id, bool* out);
```
Queries whether IMS is currently registered.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## VoLTE and Service Query
### tapi_ims_is_volte_available
```c
int tapi_ims_is_volte_available(tapi_context context, int slot_id, bool* out);
```
Queries whether VoLTE is available on the current network.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_ims_get_subscriber_uri_number
```c
int tapi_ims_get_subscriber_uri_number(tapi_context context, int slot_id, char** out);
```
Gets the IMS subscriber URI number.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_ims_get_enabled
```c
int tapi_ims_get_enabled(tapi_context context, int slot_id, bool* out);
```
Queries whether IMS is enabled.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,724 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_manager.md) \]
# Telephony Manager API
Cellular communication management interfaces, including initialization, status query, and event registration.
Header: `#include <tapi_manager.h>`
## openvela Implementation Notes
- **D-Bus Based**: TAPI Manager communicates with the Telephony Core Stack (oFono) via D-Bus, exposing standard C interfaces externally
- **SIM identification**: The manager layer does not directly handle SIM slot selection; slot-specific operations use the `slot_id` parameter in submodules such as `tapi_sim`
- **Client Handle**: Obtain a `tapi_context` via `tapi_open`; all subsequent calls take this context as the first parameter
- **Event Subscription**: Register event callbacks via `tapi_register`, unsubscribe via `tapi_unregister`
- **Synchronous vs Asynchronous**: Most interfaces are asynchronous (with callbacks); some provide `*_sync` variants for simple scenarios
## Client Connection Management
### tapi_open
```c
tapi_context tapi_open(const char* client_name, tapi_client_ready_function callback, void* user_data);
```
Open a Telephony connection and obtain a context handle.
**Parameters**:
- `client_name` Client name.
- `callback` Callback function.
- `user_data` User data passed to the callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_open_service
```c
tapi_context tapi_open_service(const char* client_name, tapi_client_ready_function callback, void* user_data, unsigned int tapi_service);
```
Open a Telephony connection.
**Parameters**:
- `client_name` Client name.
- `callback` Callback function.
- `user_data` User data passed to the callback function.
- `tapi_service` Telephony service type.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_close
```c
int tapi_close(tapi_context context);
```
Close a Telephony connection.
**Parameters**:
- `context` Telephony context handle.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Capability Query
### tapi_is_feature_supported
```c
bool tapi_is_feature_supported(tapi_feature_type feature);
```
Query whether a specified feature is supported.
**Parameters**:
- `feature` Feature name.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Radio Control
### tapi_set_radio_power
```c
int tapi_set_radio_power(tapi_context context, int slot_id, int event_id, bool state, tapi_async_function p_handle);
```
Set radio power.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `state` State.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_set_radio_power_async
```c
int tapi_set_radio_power_async(tapi_context context, int slot_id, int event_id, bool state, void* user_data, tapi_async_function p_handle);
```
Set radio power (asynchronous version).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `state` State.
- `user_data` User data passed to the callback function.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_radio_power
```c
int tapi_get_radio_power(tapi_context context, int slot_id, bool* out);
```
Get radio power state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Network Mode
### tapi_set_pref_net_mode
```c
int tapi_set_pref_net_mode(tapi_context context, int slot_id, int event_id, tapi_pref_net_mode mode, tapi_async_function p_handle);
```
Set preferred network mode.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `mode` Mode.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_pref_net_mode
```c
int tapi_get_pref_net_mode(tapi_context context, int slot_id, tapi_pref_net_mode* out);
```
Get preferred network mode.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_radio_state
```c
int tapi_get_radio_state(tapi_context context, int slot_id, tapi_radio_state* out);
```
Get radio state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Modem Information
### tapi_get_imei
```c
int tapi_get_imei(tapi_context context, int slot_id, char** out);
```
Get device IMEI.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_imeisv
```c
int tapi_get_imeisv(tapi_context context, int slot_id, char** out);
```
Get device IMEISV.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_modem_revision
```c
int tapi_get_modem_revision(tapi_context context, int slot_id, char** out);
```
Get Modem revision information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_phone_state
```c
int tapi_get_phone_state(tapi_context context, int slot_id, tapi_phone_state* state);
```
Get phone state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `state` State.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Phone Number
### tapi_get_msisdn_number
```c
int tapi_get_msisdn_number(tapi_context context, int slot_id, char** out);
```
Get SIM card phone number (MSISDN).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Modem Status and Control
### tapi_get_modem_activity_info
```c
int tapi_get_modem_activity_info(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get Modem activity information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_invoke_oem_ril_request_raw
```c
int tapi_invoke_oem_ril_request_raw(tapi_context context, int slot_id, int event_id, unsigned char oem_req[], int length, tapi_async_function p_handle);
```
Send an OEM RIL request.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `oem_req` OEM request data.
- `length` Data length.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_invoke_oem_ril_request_strings
```c
int tapi_invoke_oem_ril_request_strings(tapi_context context, int slot_id, int event_id, char* oem_req[], int length, tapi_async_function p_handle);
```
Send an OEM RIL request.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `oem_req` OEM request data.
- `length` Data length.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_enable_modem
```c
int tapi_enable_modem(tapi_context context, int slot_id, int event_id, bool enable, tapi_async_function p_handle);
```
Enable or disable Modem.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `enable` Whether to enable.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_enable_modem_abnormal_event
```c
int tapi_enable_modem_abnormal_event(tapi_context context, int slot_id, bool enable, int event_id, int module_mask, int from_event_id, int to_event_id, tapi_async_function p_handle);
```
Enable Modem abnormal event reporting.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `enable` Whether to enable.
- `event_id` Event ID for callback matching.
- `module_mask` Module mask.
- `from_event_id` Source event ID.
- `to_event_id` Target event ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_set_signal_report_threshold
```c
int tapi_set_signal_report_threshold(tapi_context context, int slot_id, int event_id, int type, tapi_async_function p_handle);
```
Set signal report threshold.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `type` Type.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_suppress_message_report
```c
int tapi_suppress_message_report(tapi_context context, int slot_id, int event_id, bool enable, tapi_async_function p_handle);
```
Suppress message reporting.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `enable` Whether to enable.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_enable_modem_stationary
```c
int tapi_enable_modem_stationary(tapi_context context, int slot_id, int event_id, bool enable, tapi_async_function p_handle);
```
Enable Modem stationary mode.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `enable` Whether to enable.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_set_modem_stationary_threshold
```c
int tapi_set_modem_stationary_threshold(tapi_context context, int slot_id, int event_id, int value, tapi_async_function p_handle);
```
Set Modem stationary threshold.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `value` Value.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_modem_status
```c
int tapi_get_modem_status(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get Modem status.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_modem_status_sync
```c
int tapi_get_modem_status_sync(tapi_context context, int slot_id, tapi_modem_state* out);
```
Get Modem status (synchronous version).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_set_fast_dormancy
```c
int tapi_set_fast_dormancy(tapi_context context, int slot_id, int event_id, bool state, tapi_async_function p_handle);
```
Set fast dormancy.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `state` State.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_phone_number
```c
int tapi_get_phone_number(tapi_context context, int slot_id, char** out);
```
Get local phone number.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Event Subscription
### tapi_register
```c
int tapi_register(tapi_context context, int slot_id, tapi_indication_msg msg, void* user_obj, tapi_async_function p_handle);
```
Register an event callback.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `msg` Message content.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_unregister
```c
int tapi_unregister(tapi_context context, int watch_id);
```
Unregister an event callback.
**Parameters**:
- `context` Telephony context handle.
- `watch_id` Watch ID (used to cancel the subscription).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Carrier Configuration
### tapi_get_carrier_config_bool
```c
int tapi_get_carrier_config_bool(tapi_context context, int slot_id, char* key, bool* out);
```
Get a boolean carrier configuration value.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `key` Key name.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_carrier_config_int
```c
int tapi_get_carrier_config_int(tapi_context context, int slot_id, char* key, int* out);
```
Get an integer carrier configuration value.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `key` Key name.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_get_carrier_config_string
```c
int tapi_get_carrier_config_string(tapi_context context, int slot_id, char* key, char** out);
```
Get a string carrier configuration value.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `key` Key name.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,439 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_network.md) \]
# Network Service API
Cellular network registration, signal strength, operator information, etc.
Header: `#include <tapi_network.h>`
## openvela Implementation Notes
- **Network selection mode**: Supports automatic selection (`select_auto`) and manual selection (`select_manual`)
- **Scanning**: `tapi_network_scan` scans for available network operators
- **Cell information**: `get_serving_cellinfos` retrieves the current serving cell, `get_neighbouring_cellinfos` retrieves neighboring cells
- **SIM identification**: Most interfaces include a `slot_id` parameter to distinguish network state across different SIM slots
- **Event subscription**: `tapi_network_register` / `tapi_network_unregister` monitor registration state and signal strength changes
## Network Selection and Scanning
### tapi_network_select_auto
```c
int tapi_network_select_auto(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Automatically select a network.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_select_manual
```c
int tapi_network_select_manual(tapi_context context, int slot_id, int event_id, tapi_operator_info* network, tapi_async_function p_handle);
```
Manually select a network.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `network` Network information.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_scan
```c
int tapi_network_scan(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Scan for available network operators.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Cell Information
### tapi_network_get_serving_cellinfos
```c
int tapi_network_get_serving_cellinfos(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get serving cell information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_get_neighbouring_cellinfos
```c
int tapi_network_get_neighbouring_cellinfos(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get neighboring cell information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Voice Network State
### tapi_network_is_voice_registered
```c
int tapi_network_is_voice_registered(tapi_context context, int slot_id, bool* out);
```
Query whether voice service is registered.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_is_voice_emergency_only
```c
int tapi_network_is_voice_emergency_only(tapi_context context, int slot_id, bool* out);
```
Query whether only emergency calls are available.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_get_voice_network_type
```c
int tapi_network_get_voice_network_type(tapi_context context, int slot_id, tapi_network_type* out);
```
Get the voice network type.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_is_voice_roaming
```c
int tapi_network_is_voice_roaming(tapi_context context, int slot_id, bool* out);
```
Query whether voice is roaming.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Operator Information
### tapi_network_get_display_name
```c
int tapi_network_get_display_name(tapi_context context, int slot_id, char** out);
```
Get the operator display name.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Signal Strength
### tapi_network_get_signalstrength
```c
int tapi_network_get_signalstrength(tapi_context context, int slot_id, tapi_signal_strength* out);
```
Get the signal strength.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Registration Information
### tapi_network_get_registration_info
```c
int tapi_network_get_registration_info(tapi_context context, int slot_id, int event_id, tapi_async_function p_handle);
```
Get network registration information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Reporting Rate and Events
### tapi_network_set_cell_info_list_rate
```c
int tapi_network_set_cell_info_list_rate(tapi_context context, int slot_id, int event_id, u_int32_t period, tapi_async_function p_handle);
```
Set the cell information list reporting rate.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `period` Period in milliseconds.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_register
```c
int tapi_network_register(tapi_context context, int slot_id, tapi_indication_msg msg, void* user_obj, tapi_async_function p_handle);
```
Register for network event notifications.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `msg` Message type.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_unregister
```c
int tapi_network_unregister(tapi_context context, int watch_id);
```
Unregister from network event notifications.
**Parameters**:
- `context` Telephony context handle.
- `watch_id` Watch ID (used to cancel the subscription).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## MCC / MNC
### tapi_network_get_mcc
```c
int tapi_network_get_mcc(tapi_context context, int slot_id, char** mcc);
```
Get the Mobile Country Code.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `mcc` Mobile Country Code.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_get_mnc
```c
int tapi_network_get_mnc(tapi_context context, int slot_id, char** mnc);
```
Get the Mobile Network Code.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `mnc` Mobile Network Code.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_get_operator_status
```c
int tapi_network_get_operator_status(tapi_context context, int slot_id, int* out);
```
Get the operator status.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_get_operator_name
```c
int tapi_network_get_operator_name(tapi_context context, int slot_id, char** out);
```
Get the operator name.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_network_get_reg_state
```c
int tapi_network_get_reg_state(tapi_context context, int slot_id, tapi_registration_state* out);
```
Get the network registration state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,303 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_phone.md) \]
# Telephony Phone Service API
Simplified phone service interface for lightweight clients. Compared to `tapi_call`, this module provides a more compact call control encapsulation and integrates audio type control, radio power switch, and WTP (Wireless Telephony Profile) companion interfaces.
Header: `#include <tapi_phone.h>`
## openvela Implementation Notes
- **Client session**: Started via `tapi_start_phone_service_client`, stopped via `tapi_stop_phone_service_client`
- **Callback registration**: Use `tapi_client_register_callbacks` to register a unified callback set for call events
- **No tapi_context required**: This interface internally manages the connection to the service; callers do not need to hold a `tapi_context`
- **WTP support**: Encapsulates WTP (Wireless Telephony Profile) adaptation for Bluetooth-paired watches/devices
- **Use cases**: Embedded wearable devices, simple call clients
## Service Lifecycle
### tapi_start_phone_service_client
```c
int tapi_start_phone_service_client(const char* client_name);
```
Start the phone service client.
**Parameters**:
- `client_name` Client name.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stop_phone_service_client
```c
int tapi_stop_phone_service_client(void);
```
Stop the phone service client.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_client_register_callbacks
```c
int tapi_client_register_callbacks(void* callbacks);
```
Register the client callback set.
**Parameters**:
- `callbacks` Pointer to the callback function set.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_client_unregister_callbacks
```c
int tapi_client_unregister_callbacks(void);
```
Unregister the client callbacks.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Call Control
### tapi_dial_call
```c
int tapi_dial_call(const char* number);
```
Dial a call.
**Parameters**:
- `number` Phone number string to dial.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_answer_call
```c
int tapi_answer_call(void);
```
Answer an incoming call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_reject_call
```c
int tapi_reject_call(void);
```
Reject an incoming call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_hangup_call
```c
int tapi_hangup_call(void);
```
Hang up the current call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_hold_call
```c
int tapi_hold_call(void);
```
Hold the current call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_hold_and_answer_call
```c
int tapi_hold_and_answer_call(void);
```
Hold the current call and answer a new incoming call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_release_and_answer_call
```c
int tapi_release_and_answer_call(void);
```
Release the current call and answer a new incoming call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_merge_call
```c
int tapi_merge_call(void);
```
Merge multiple calls into a conference call.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_send_tones
```c
int tapi_send_tones(const char* tones);
```
Send a DTMF tone sequence.
**Parameters**:
- `tones` DTMF string (`0-9 * # A-D`).
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Audio and Radio Control
### tapi_client_set_audio_type
```c
int tapi_client_set_audio_type(int type);
```
Set the audio type used during a call.
**Parameters**:
- `type` Audio type enumeration value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_client_set_radio_power
```c
int tapi_client_set_radio_power(bool enabled);
```
Simplified radio power switch.
**Parameters**:
- `enabled` `true` to enable radio, `false` to disable.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## WTP (Wireless Telephony Profile)
### tapi_client_wtp_register_cb
```c
int tapi_client_wtp_register_cb(void* callbacks);
```
Register WTP event callbacks.
**Parameters**:
- `callbacks` Pointer to the WTP callback set.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_client_wtp_unregister_cb
```c
int tapi_client_wtp_unregister_cb(void);
```
Unregister WTP event callbacks.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_wtp_set_local_info
```c
int tapi_wtp_set_local_info(const char* info);
```
Set WTP local information (device identity, capabilities, etc.).
**Parameters**:
- `info` Local information string.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_wtp_modify_discovery
```c
int tapi_wtp_modify_discovery(int mode);
```
Modify the WTP discovery mode.
**Parameters**:
- `mode` Discovery mode enumeration value.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_wtp_modify_visibility
```c
int tapi_wtp_modify_visibility(int visibility);
```
Modify the WTP visibility configuration.
**Parameters**:
- `visibility` Visibility enumeration value.
**Returns**:
Returns `0` on success, or a negative error code on failure.

View File

@ -1,131 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_phonebook.md) \]
# Telephony Phonebook API
SIM card phonebook management interfaces, supporting ADN (Abbreviated Dialling Numbers) and FDN (Fixed Dialling Numbers) entries.
Header: `#include <tapi_phonebook.h>`
## openvela Implementation Notes
- **ADN**: Abbreviated Dialling Numbers, regular numbers stored on the SIM card
- **FDN**: Fixed Dialling Numbers; when enabled, the phone can only dial numbers in the FDN list, protected by PIN2
- **FDN operations require PIN2**: `insert_fdn_entry` / `delete_fdn_entry` / `update_fdn_entry` calls require PIN2
- **SIM identification**: All interfaces include a `slot_id` parameter
- **Asynchronous callbacks**: All operations return results asynchronously via `tapi_async_function`
## ADN Phonebook
### tapi_phonebook_load_adn_entries
```c
int tapi_phonebook_load_adn_entries(tapi_context context, int slot_id, int event_id,
tapi_async_function p_handle);
```
Load ADN phonebook entries from the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function, returns the ADN entry list on callback.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## FDN Fixed Dialling
### tapi_phonebook_load_fdn_entries
```c
int tapi_phonebook_load_fdn_entries(tapi_context context, int slot_id, int event_id,
tapi_async_function p_handle);
```
Load FDN entries from the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `p_handle` Asynchronous callback function, returns the FDN entry list on callback.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_phonebook_insert_fdn_entry
```c
int tapi_phonebook_insert_fdn_entry(tapi_context context, int slot_id, int event_id,
char* name, char* number, char* pin2,
tapi_async_function p_handle);
```
Insert a new entry into the FDN list (requires PIN2 verification).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `name` Contact name.
- `number` Phone number.
- `pin2` SIM card PIN2 code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_phonebook_update_fdn_entry
```c
int tapi_phonebook_update_fdn_entry(tapi_context context, int slot_id, int event_id,
int fdn_idx, char* new_name, char* new_number,
char* pin2, tapi_async_function p_handle);
```
Update an existing FDN entry (requires PIN2 verification).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `fdn_idx` Index of the entry to update.
- `new_name` New contact name.
- `new_number` New phone number.
- `pin2` SIM card PIN2 code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_phonebook_delete_fdn_entry
```c
int tapi_phonebook_delete_fdn_entry(tapi_context context, int slot_id, int event_id,
int fdn_idx, char* pin2,
tapi_async_function p_handle);
```
Delete a specified FDN entry (requires PIN2 verification).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `fdn_idx` Index of the entry to delete.
- `pin2` SIM card PIN2 code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.

View File

@ -1,456 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_sim.md) \]
# SIM Card Management API
SIM card status query and management.
Header file: `#include <tapi_sim.h>`
## openvela Implementation Notes
- **SIM management**: All interfaces include `slot_id` parameter for SIM card identification
- **PIN management**: Provides `enter_pin` / `change_pin` / `reset_pin` / `lock_pin` / `unlock_pin` for complete PIN/PUK workflows
- **APDU channel**: Use `open_logical_channel` / `close_logical_channel` / `transmit_apdu_*` to send APDU commands directly to the SIM card
- **UICC switch**: Control SIM card enablement state via `get_uicc_enablement` / `set_uicc_enablement`
- **Event subscription**: `tapi_sim_register` / `tapi_sim_unregister` to monitor SIM card state changes
## SIM Status Query
### tapi_sim_has_icc_card
```c
int tapi_sim_has_icc_card(tapi_context context, int slot_id, bool* out);
```
Query whether a SIM card is inserted.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_get_sim_state
```c
int tapi_sim_get_sim_state(tapi_context context, int slot_id, int* out);
```
Get the SIM card state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_get_sim_operator
```c
int tapi_sim_get_sim_operator(tapi_context context, int slot_id, int length, char* out);
```
Get the SIM card operator information.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `length` Data length.
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_get_sim_operator_name
```c
int tapi_sim_get_sim_operator_name(tapi_context context, int slot_id, char** out);
```
Get the SIM card operator name.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_get_sim_iccid
```c
int tapi_sim_get_sim_iccid(tapi_context context, int slot_id, char** out);
```
Get the SIM card ICCID.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_get_subscriber_id
```c
int tapi_sim_get_subscriber_id(tapi_context context, int slot_id, char** out);
```
Get the subscriber identity (IMSI).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Event Subscription
### tapi_sim_register
```c
int tapi_sim_register(tapi_context context, int slot_id, tapi_indication_msg msg, void* user_obj, tapi_async_function p_handle);
```
Register a SIM event callback.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `msg` Message content.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_unregister
```c
int tapi_sim_unregister(tapi_context context, int watch_id);
```
Unregister a SIM event callback.
**Parameters**:
- `context` Telephony context handle.
- `watch_id` Watch ID (used to cancel the subscription).
**Returns**:
Returns 0 on success, or a negative error code on failure.
## PIN Management
### tapi_sim_change_pin
```c
int tapi_sim_change_pin(tapi_context context, int slot_id, int event_id, char* pin_type, char* old_pin, char* new_pin, tapi_async_function p_handle);
```
Change the SIM card PIN code.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `pin_type` PIN code type.
- `old_pin` Old PIN code.
- `new_pin` New PIN code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_enter_pin
```c
int tapi_sim_enter_pin(tapi_context context, int slot_id, int event_id, char* pin_type, char* pin, tapi_async_function p_handle);
```
Enter the SIM card PIN code.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `pin_type` PIN code type.
- `pin` PIN code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_reset_pin
```c
int tapi_sim_reset_pin(tapi_context context, int slot_id, int event_id, char* puk_type, char* puk, char* new_pin, tapi_async_function p_handle);
```
Reset the SIM card PIN using PUK code.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `puk_type` PUK code type.
- `puk` PUK code.
- `new_pin` New PIN code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_lock_pin
```c
int tapi_sim_lock_pin(tapi_context context, int slot_id, int event_id, char* pin_type, char* pin, tapi_async_function p_handle);
```
Lock the SIM card PIN.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `pin_type` PIN code type.
- `pin` PIN code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_unlock_pin
```c
int tapi_sim_unlock_pin(tapi_context context, int slot_id, int event_id, char* pin_type, char* pin, tapi_async_function p_handle);
```
Unlock the SIM card PIN.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `pin_type` PIN code type.
- `pin` PIN code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## APDU Logical Channel
### tapi_sim_open_logical_channel
```c
int tapi_sim_open_logical_channel(tapi_context context, int slot_id, int event_id, unsigned char aid[], int len, tapi_async_function p_handle);
```
Open a SIM card logical channel.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `aid` Application ID.
- `len` Length.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_close_logical_channel
```c
int tapi_sim_close_logical_channel(tapi_context context, int slot_id, int event_id, int session_id, tapi_async_function p_handle);
```
Close a SIM card logical channel.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `session_id` Session ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_transmit_apdu_logical_channel
```c
int tapi_sim_transmit_apdu_logical_channel(tapi_context context, int slot_id, int event_id, int session_id, unsigned char pdu[], int len, tapi_async_function p_handle);
```
Transmit an APDU command through the logical channel.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `session_id` Session ID.
- `pdu` PDU data.
- `len` Length.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_transmit_apdu_basic_channel
```c
int tapi_sim_transmit_apdu_basic_channel(tapi_context context, int slot_id, int event_id, unsigned char pdu[], int len, tapi_async_function p_handle);
```
Transmit an APDU command through the basic channel.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `pdu` PDU data.
- `len` Length.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## UICC Switch
### tapi_sim_get_uicc_enablement
```c
int tapi_sim_get_uicc_enablement(tapi_context context, int slot_id, tapi_sim_uicc_app_state* out);
```
Get the UICC enablement state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_set_uicc_enablement
```c
int tapi_sim_set_uicc_enablement(tapi_context context, int slot_id, int event_id, int state, tapi_async_function p_handle);
```
Set the UICC enablement state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `event_id` Event ID for callback matching.
- `state` State.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sim_get_sim_invalid
```c
int tapi_sim_get_sim_invalid(tapi_context context, int slot_id, int* out);
```
Get the SIM card invalid state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,293 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_sms.md) \]
# SMS Management API
SMS sending and receiving.
Header: `#include <tapi_sms.h>`
## openvela Implementation Notes
- **Text and Data SMS**: `send_message` sends text SMS, `send_data_message` sends binary PDU
- **Service Center Address**: Configure the carrier SMS gateway via `set_service_center_address` / `get_service_center_address`
- **Delivery Report**: Toggle delivery reports with `enable_delivery_report`
- **SIM Card Storage**: Provides `get_all_messages_from_sim` / `copy_message_to_sim` / `delete_message_from_sim` to operate on SMS stored on the SIM card
- **Event Subscription**: `tapi_sms_register` listens for incoming/outgoing message events
## Sending SMS
### tapi_sms_send_message
```c
int tapi_sms_send_message(tapi_context context, int slot_id, int sms_id, char* number, char* text, int event_id, tapi_async_function p_handle);
```
Sends a text SMS message.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `sms_id` SMS message ID.
- `number` Phone number.
- `text` Text content.
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_send_data_message
```c
int tapi_sms_send_data_message(tapi_context context, int slot_id, int sms_id, char* dest_addr, unsigned int port, char* text, int event_id, tapi_async_function p_handle);
```
Sends a data SMS message.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `sms_id` SMS message ID.
- `dest_addr` Destination number.
- `port` Port number.
- `text` Text content.
- `event_id` Event ID for callback matching.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Service Center and Delivery Report
### tapi_sms_set_service_center_address
```c
bool tapi_sms_set_service_center_address(tapi_context context, int slot_id, char* number);
```
Sets the SMSC (Short Message Service Center) address.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `number` SMSC phone number.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_get_service_center_address
```c
int tapi_sms_get_service_center_address(tapi_context context, int slot_id, char** number);
```
Gets the SMSC (Short Message Service Center) address.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `number` Pointer to receive the SMSC phone number.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_enable_delivery_report
```c
int tapi_sms_enable_delivery_report(tapi_context context, int slot_id, bool enable);
```
Enables or disables SMS delivery reports.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `enable` Whether to enable delivery reports.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_get_delivery_report_status
```c
int tapi_sms_get_delivery_report_status(tapi_context context, int slot_id, bool* out);
```
Gets the current delivery report status.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `out` Output parameter to receive the status.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## SIM Card SMS Storage
### tapi_sms_get_all_messages_from_sim
```c
int tapi_sms_get_all_messages_from_sim(tapi_context context, int slot_id, tapi_message_list* list, tapi_async_function p_handle);
```
Retrieves all SMS messages stored on the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `list` Message list to populate.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_copy_message_to_sim
```c
int tapi_sms_copy_message_to_sim(tapi_context context, int slot_id, char* number, char* text, char* send_time, int type);
```
Copies an SMS message to the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `number` Phone number.
- `text` Text content.
- `send_time` Send time.
- `type` Message type.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_delete_message_from_sim
```c
int tapi_sms_delete_message_from_sim(tapi_context context, int slot_id, int index);
```
Deletes an SMS message from the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `index` Message index on the SIM card.
**Returns**:
Returns 0 on success, or a negative error code on failure.
## Event Subscription and Default Slot
### tapi_sms_register
```c
int tapi_sms_register(tapi_context context, int slot_id, tapi_indication_msg msg, void* user_obj, tapi_async_function p_handle);
```
Registers for SMS event notifications.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
- `msg` Indication message type.
- `user_obj` User object pointer.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_unregister
```c
int tapi_sms_unregister(tapi_context context, int watch_id);
```
Unregisters from SMS event notifications.
**Parameters**:
- `context` Telephony context handle.
- `watch_id` Watch ID (used to cancel the subscription).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_set_default_slot
```c
int tapi_sms_set_default_slot(tapi_context context, int slot_id);
```
Sets the default SIM slot for SMS.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID (0 or 1).
**Returns**:
Returns 0 on success, or a negative error code on failure.
### tapi_sms_get_default_slot
```c
int tapi_sms_get_default_slot(tapi_context context, int* out);
```
Gets the default SIM slot for SMS.
**Parameters**:
- `context` Telephony context handle.
- `out` Output parameter to receive the default slot ID.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,491 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_ss.md) \]
# Telephony Supplementary Services (SS) API
Supplementary Services (SS) are value-added call capabilities defined by 3GPP cellular standards, including Call Barring, Call Forwarding, Calling Line Identification Restriction/Presentation (CLIR/CLIP), Call Waiting, USSD, etc.
Header file: `#include <tapi_ss.h>`
## openvela Implementation Notes
- **Call Barring**: `tapi_ss_*_call_barring*` series controls the number range for outgoing/incoming calls
- **Call Forwarding**: `tapi_ss_*_call_forwarding*` series configures unconditional/busy/no-reply/unreachable forwarding
- **CLIR/CLIP**: Calling line identification display and restriction via `calling_line_restriction` and `calling_line_presentation_info` interfaces
- **USSD**: `tapi_ss_send_ussd` sends `*#xxxx#` commands, `tapi_ss_cancel_ussd` cancels the session
- **FDN**: Fixed Dialing Number switch via `tapi_ss_enable_fdn` / `tapi_ss_query_fdn`
- **SIM identification**: All interfaces include `slot_id`
- **Asynchronous callback**: All operations use `tapi_async_function`
## Call Barring
### tapi_ss_request_call_barring
```c
int tapi_ss_request_call_barring(tapi_context context, int slot_id, int event_id,
char* fac, char* pin2,
tapi_async_function p_handle);
```
Request a specific type of call barring (by FAC code).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `fac` Call barring FAC code (e.g., `"OI"`, `"IR"`, etc.).
- `pin2` SIM card PIN2 code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_set_call_barring_option
```c
int tapi_ss_set_call_barring_option(tapi_context context, int slot_id, int event_id,
char* facility, char* pin2,
tapi_async_function p_handle);
```
Set call barring options.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `facility` Barring type string.
- `pin2` SIM card PIN2 code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_get_call_barring_option
```c
int tapi_ss_get_call_barring_option(tapi_context context, int slot_id,
const char* service_type, char** out);
```
Query the current call barring configuration.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `service_type` Service type string.
- `out` Output parameter, returns the configuration string.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_change_call_barring_password
```c
int tapi_ss_change_call_barring_password(tapi_context context, int slot_id, int event_id,
char* old_pin, char* new_pin,
tapi_async_function p_handle);
```
Change the call barring service password.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `old_pin` Old password.
- `new_pin` New password.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_disable_all_call_barrings
```c
int tapi_ss_disable_all_call_barrings(tapi_context context, int slot_id, int event_id,
char* passwd, tapi_async_function p_handle);
```
Disable all call barrings.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `passwd` Service password.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_disable_all_incoming
```c
int tapi_ss_disable_all_incoming(tapi_context context, int slot_id,
int event_id, char* passwd,
tapi_async_function p_handle);
```
Disable all incoming call barrings.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `passwd` Service password.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_disable_all_outgoing
```c
int tapi_ss_disable_all_outgoing(tapi_context context, int slot_id,
int event_id, char* passwd,
tapi_async_function p_handle);
```
Disable all outgoing call barrings.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `passwd` Service password.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Call Forwarding
### tapi_ss_query_call_forwarding_option
```c
int tapi_ss_query_call_forwarding_option(tapi_context context, int slot_id, int event_id,
int cf_reason, tapi_async_function p_handle);
```
Query call forwarding configuration.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `cf_reason` Forwarding type (unconditional/busy/no-reply/unreachable, see `tapi_call_forward_option`).
- `p_handle` Asynchronous callback function, returns `tapi_call_forwarding_info` on callback.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_set_call_forwarding_option
```c
int tapi_ss_set_call_forwarding_option(tapi_context context, int slot_id, int event_id,
tapi_call_forwarding_info* info,
tapi_async_function p_handle);
```
Set call forwarding configuration.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `info` Call forwarding configuration structure.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## USSD Session
### tapi_ss_initiate_service
```c
int tapi_ss_initiate_service(tapi_context context, int slot_id, int event_id,
char* command, tapi_async_function p_handle);
```
Initiate an SS service command (USSD/SS string format, e.g., `*#06#`).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `command` Command string.
- `p_handle` Asynchronous callback function, returns `tapi_ss_initiate_info` on callback.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_get_ussd_state
```c
int tapi_get_ussd_state(tapi_context context, int slot_id, char** out);
```
Query the current USSD session state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `out` Output parameter, returns the state string (e.g., `"idle"`, `"user-response"`).
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_send_ussd
```c
int tapi_ss_send_ussd(tapi_context context, int slot_id, int event_id, char* reply,
tapi_async_function p_handle);
```
Send a USSD reply message.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `reply` Reply string.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_cancel_ussd
```c
int tapi_ss_cancel_ussd(tapi_context context, int slot_id, int event_id,
tapi_async_function p_handle);
```
Cancel the current USSD session.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Call Waiting
### tapi_ss_set_call_waiting
```c
int tapi_ss_set_call_waiting(tapi_context context, int slot_id, int event_id, bool enable,
tapi_async_function p_handle);
```
Enable or disable call waiting.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `enable` `true` to enable, `false` to disable.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_get_call_waiting
```c
int tapi_ss_get_call_waiting(tapi_context context, int slot_id, int event_id,
tapi_async_function p_handle);
```
Query the call waiting switch state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `p_handle` Asynchronous callback function, returns the current state on callback.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## CLIR / CLIP (Calling Line Identification)
### tapi_ss_get_calling_line_presentation_info
```c
int tapi_ss_get_calling_line_presentation_info(tapi_context context, int slot_id,
int event_id, tapi_async_function p_handle);
```
Query the Calling Line Identification Presentation (CLIP) state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_set_calling_line_restriction
```c
int tapi_ss_set_calling_line_restriction(tapi_context context, int slot_id, int event_id,
tapi_clir_status status,
tapi_async_function p_handle);
```
Set the Calling Line Identification Restriction (CLIR) state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `status` CLIR status enum value (`CLIR_DEFAULT` / `CLIR_INVOCATION` / `CLIR_SUPPRESSION`).
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_get_calling_line_restriction_info
```c
int tapi_ss_get_calling_line_restriction_info(tapi_context context, int slot_id,
int event_id, tapi_async_function p_handle);
```
Query the Calling Line Identification Restriction (CLIR) state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## FDN (Fixed Dialing Number) Switch
### tapi_ss_enable_fdn
```c
int tapi_ss_enable_fdn(tapi_context context, int slot_id, int event_id,
bool enable, char* pin2, tapi_async_function p_handle);
```
Enable or disable FDN mode (requires PIN2).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `enable` `true` to enable FDN, `false` to disable.
- `pin2` SIM card PIN2 code.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_ss_query_fdn
```c
int tapi_ss_query_fdn(tapi_context context, int slot_id, int event_id,
tapi_async_function p_handle);
```
Query the FDN switch state.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `event_id` Event ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Event Subscription
### tapi_ss_register
```c
int tapi_ss_register(tapi_context context, int slot_id, tapi_indication_msg msg,
void* user_obj, tapi_async_function p_handle);
```
Register an SS event callback.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `msg` Event type to monitor.
- `user_obj` User data.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns the watch ID on success, or a negative error code on failure.
### tapi_ss_unregister
```c
int tapi_ss_unregister(tapi_context context, int watch_id);
```
Unregister an SS event subscription.
**Parameters**:
- `context` Telephony context handle.
- `watch_id` Watch ID returned during subscription.
**Returns**:
Returns `0` on success, or a negative error code on failure.

View File

@ -1,603 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/telephony/telephony_stk.md) \]
# Telephony SIM Toolkit (STK) API
SIM Application Toolkit (STK / CAT) provides carrier-provisioned interactive menus and event handling capabilities on the SIM card. Common use cases include carrier value-added menus, service password management, and URL browser launching.
Header file: `#include <tapi_stk.h>`
## openvela Implementation Notes
- **Agent mode**: The application registers as an "STK Agent" with TAPI. Display/input/confirmation requests initiated proactively by the SIM card are delivered to the application through Agent callbacks.
- **Registration levels**: Supports per-slot Agent (via `tapi_stk_agent_register`) and default Agent (system default UI).
- **Main menu**: `tapi_stk_get_main_menu*` queries the main menu structure provided by the SIM card.
- **Proactive Command responses**: The `tapi_stk_handle_agent_*` family of interfaces is used to send the Agent's responses to SIM card proactive commands back to the SIM.
- **SIM identification**: All interfaces include a `slot_id` parameter.
## Agent Registration
### tapi_stk_agent_register
```c
int tapi_stk_agent_register(tapi_context context, int slot_id,
char* agent_id, tapi_async_function p_handle);
```
Registers an STK Agent for the specified SIM card slot.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `agent_id` Agent identifier string.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_agent_unregister
```c
int tapi_stk_agent_unregister(tapi_context context, int slot_id,
char* agent_id, tapi_async_function p_handle);
```
Unregisters an STK Agent.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `agent_id` Agent identifier string.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_default_agent_register
```c
int tapi_stk_default_agent_register(tapi_context context, int slot_id,
char* agent_id, tapi_async_function p_handle);
```
Registers as the default STK Agent (global fallback).
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `agent_id` Agent identifier string.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_default_agent_unregister
```c
int tapi_stk_default_agent_unregister(tapi_context context, int slot_id,
tapi_async_function p_handle);
```
Unregisters the default STK Agent.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_agent_interface_register
```c
int tapi_stk_agent_interface_register(tapi_context context, int slot_id, char* agent_id,
tapi_stk_agent_interface* iface);
```
Registers the concrete interface implementation (callback function set) at the Agent layer.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `agent_id` Agent identifier string.
- `iface` Pointer to the Agent interface callback structure.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_agent_interface_unregister
```c
int tapi_stk_agent_interface_unregister(tapi_context context, char* agent_id);
```
Unregisters the Agent interface implementation.
**Parameters**:
- `context` Telephony context handle.
- `agent_id` Agent identifier string.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_default_agent_interface_register
```c
int tapi_stk_default_agent_interface_register(tapi_context context, int slot_id,
tapi_stk_agent_interface* iface);
```
Registers the interface implementation for the default Agent.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `iface` Pointer to the Agent interface callback structure.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_default_agent_interface_unregister
```c
int tapi_stk_default_agent_interface_unregister(tapi_context context, int slot_id);
```
Unregisters the interface implementation of the default Agent.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Main Menu and Idle Mode
### tapi_stk_select_item
```c
int tapi_stk_select_item(tapi_context context, int slot_id,
int item_idx, tapi_async_function p_handle);
```
Selects an item from the main menu, triggering the SIM card's service response.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `item_idx` Item index.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_get_idle_mode_text
```c
int tapi_stk_get_idle_mode_text(tapi_context context, int slot_id, char** text);
```
Queries the idle mode display text set by the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `text` Output parameter, returns the text string.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_get_idle_mode_icon
```c
int tapi_stk_get_idle_mode_icon(tapi_context context, int slot_id, char** icon);
```
Queries the idle mode icon identifier set by the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `icon` Output parameter, returns the icon identifier string.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_get_main_menu
```c
int tapi_stk_get_main_menu(tapi_context context, int slot_id, int* length,
tapi_stk_menu_item out[]);
```
Retrieves the list of main menu items provided by the SIM card.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `length` Input/output parameter: on input specifies buffer capacity, on output returns the actual number of items.
- `out` Output buffer to receive the menu item array.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_get_main_menu_title
```c
int tapi_stk_get_main_menu_title(tapi_context context, int slot_id, char** title);
```
Queries the main menu title.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `title` Output parameter, returns the title string.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_get_main_menu_icon
```c
int tapi_stk_get_main_menu_icon(tapi_context context, int slot_id, int* icon);
```
Queries the main menu icon number.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `icon` Output parameter, returns the icon number.
**Returns**:
Returns `0` on success, or a negative error code on failure.
## Agent Response Handling
The following interfaces are used by Agent implementations to send proactive command responses back to the SIM card. All interfaces return `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_selection
```c
int tapi_stk_handle_agent_request_selection(tapi_context context, int slot_id,
char* agent_id, int selection,
tapi_async_function p_handle);
```
Handles the SIM card's menu item selection request by sending back the index of the item selected by the user.
**Parameters**:
- `context` Telephony context handle.
- `slot_id` SIM card slot ID.
- `agent_id` Agent identifier string.
- `selection` Index of the item selected by the user.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_display_text
```c
int tapi_stk_handle_agent_display_text(tapi_context context, int slot_id,
char* agent_id, int result,
tapi_async_function p_handle);
```
Responds to the SIM card's text display request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `result` Display operation result (whether the user confirmed, etc.).
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_input
```c
int tapi_stk_handle_agent_request_input(tapi_context context, int slot_id,
char* agent_id, char* input,
tapi_async_function p_handle);
```
Responds to the SIM card's string input request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `input` String entered by the user.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_digits
```c
int tapi_stk_handle_agent_request_digits(tapi_context context, int slot_id,
char* agent_id, char* digits,
tapi_async_function p_handle);
```
Responds to the SIM card's digit sequence input request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `digits` Digit sequence entered by the user.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_key
```c
int tapi_stk_handle_agent_request_key(tapi_context context, int slot_id,
char* agent_id, char key,
tapi_async_function p_handle);
```
Responds to the SIM card's single key input request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `key` Key character entered by the user.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_digit
```c
int tapi_stk_handle_agent_request_digit(tapi_context context, int slot_id,
char* agent_id, char digit,
tapi_async_function p_handle);
```
Responds to the SIM card's single digit input request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `digit` Single digit character entered by the user.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_quick_digit
```c
int tapi_stk_handle_agent_request_quick_digit(tapi_context context, int slot_id,
char* agent_id, char digit,
tapi_async_function p_handle);
```
Responds to the SIM card's quick digit input request (no echo required).
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `digit` Single digit character entered by the user.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_request_confirmation
```c
int tapi_stk_handle_agent_request_confirmation(tapi_context context, int slot_id,
char* agent_id, bool confirmed,
tapi_async_function p_handle);
```
Responds to the SIM card's confirmation/cancellation request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `confirmed` Whether the user confirmed.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_confirm_call_setup
```c
int tapi_stk_handle_agent_confirm_call_setup(tapi_context context, int slot_id,
char* agent_id, bool confirmed,
tapi_async_function p_handle);
```
Responds to the SIM card's call-setup confirmation request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `confirmed` Whether the user confirmed the outgoing call.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_play_tone
```c
int tapi_stk_handle_agent_play_tone(tapi_context context, int slot_id,
char* agent_id, int result,
tapi_async_function p_handle);
```
Responds to the SIM card's play tone request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `result` Playback result.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_loop_tone
```c
int tapi_stk_handle_agent_loop_tone(tapi_context context, int slot_id,
char* agent_id, int result,
tapi_async_function p_handle);
```
Responds to the SIM card's loop tone request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `result` Playback result.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_display_action_information
```c
int tapi_stk_handle_agent_display_action_information(tapi_context context, int slot_id,
char* agent_id, int result,
tapi_async_function p_handle);
```
Responds to the SIM card's action progress information display request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `result` Display operation result.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_confirm_launch_browser
```c
int tapi_stk_handle_agent_confirm_launch_browser(tapi_context context, int slot_id,
char* agent_id, bool confirmed,
tapi_async_function p_handle);
```
Responds to the SIM card's browser launch confirmation request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `confirmed` Whether the user confirmed launching the browser.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_display_action
```c
int tapi_stk_handle_agent_display_action(tapi_context context, int slot_id,
char* agent_id, int result,
tapi_async_function p_handle);
```
Responds to the SIM card's action status update request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `result` Operation result.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.
### tapi_stk_handle_agent_confirm_open_channel
```c
int tapi_stk_handle_agent_confirm_open_channel(tapi_context context, int slot_id,
char* agent_id, bool confirmed,
tapi_async_function p_handle);
```
Responds to the SIM card's open data channel confirmation request.
**Parameters**:
- `context` / `slot_id` / `agent_id` Same as above.
- `confirmed` Whether the user confirmed opening the channel.
- `p_handle` Asynchronous callback function.
**Returns**:
Returns `0` on success, or a negative error code on failure.

View File

@ -1,622 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/framework/uorb.md) \]
# uORB API
uORB is the publish/subscribe message bus of openvela, used for asynchronous data communication between processes or threads.
Header: `#include <uORB/uORB.h>`
## openvela Implementation Notes
- **Configuration Dependencies**: Requires `CONFIG_USENSOR` and `CONFIG_UORB` to be enabled
- **Cross-core Communication**: Supports cross-core topic transport when `CONFIG_SENSORS_RPMSG` is enabled
- **Built-in Sensors**: Provides 34 predefined sensor topics (accelerometer, gyroscope, GPS, etc.)
- **Custom Topics**: Defined via `ORB_DECLARE`, `ORB_DEFINE`, and `ORB_ID` macros
- **Debug Tools**: The `uorb listener` tool can monitor topic data (requires `CONFIG_DEBUG_UORB`)
## Device Management
### orb_open
```c
int orb_open(const char *name, int instance, int flags);
```
Opens the topic device node with the specified name and instance.
### orb_close
```c
int orb_close(int fd);
```
Closes a file descriptor.
### orb_unlink_multi
```c
int orb_unlink_multi(const struct orb_metadata *meta, int instance);
```
Removes a topic node.
## Publish Interface
### orb_advertise_multi_queue_info
```c
int orb_advertise_multi_queue_info(const struct orb_metadata *meta, const void *data, int *instance, unsigned int queue_size, orb_info_t *info);
```
Performs the initial advertisement (publisher registration) of a topic, creating the corresponding topic node under `/dev/uorb` and publishing initial data.
### orb_advertise_multi_queue_persist
```c
int orb_advertise_multi_queue_persist_info(const struct orb_metadata *meta, const void *data, int *instance, unsigned int queue_size, orb_info_t *info);
```
`orb_advertise_multi_queue_persist` is similar to `orb_advertise_multi_queue`, but guarantees that all subscribers (including future ones) can access the current and subsequent published data.
### orb_unadvertise
```c
static inline int orb_unadvertise(int fd) { return orb_close(fd);
```
Cancels a topic advertisement.
### orb_publish_multi
```c
ssize_t orb_publish_multi(int fd, const void *data, size_t len);
```
Publishes new data of a specified length to a topic. After publication, all waiting subscribers are woken up; non-waiting subscribers can use `orb_check` to check whether the topic has been updated.
### orb_advertise
```c
static inline int orb_advertise(const struct orb_metadata *meta, const void *data);
```
Advertises a topic. Equivalent to `orb_advertise_multi(meta, data, NULL)`, creating default instance 0.
**Parameters**:
- `meta` Pointer to topic metadata.
- `data` Initial data to publish (may be `NULL`).
**Returns**:
Returns the advertiser file descriptor on success, or a negative value on failure with `errno` set.
### orb_advertise_multi
```c
static inline int orb_advertise_multi(const struct orb_metadata *meta,
const void *data, int *instance);
```
Advertises a topic with an instance ID, used for multi-instance topic scenarios.
**Parameters**:
- `meta` Pointer to topic metadata.
- `data` Initial data to publish.
- `instance` Input/output parameter that returns the newly created instance ID.
**Returns**:
Returns the file descriptor on success, or a negative value on failure.
### orb_advertise_queue
```c
static inline int orb_advertise_queue(const struct orb_metadata *meta,
const void *data, unsigned int queue_size);
```
Advertises a topic with a queue. When the queue size is greater than 1, multiple historical data entries are cached.
**Parameters**:
- `meta` Pointer to topic metadata.
- `data` Initial data.
- `queue_size` Queue depth.
**Returns**:
Returns the file descriptor on success, or a negative value on failure.
### orb_advertise_multi_queue
```c
static inline int orb_advertise_multi_queue(const struct orb_metadata *meta,
const void *data, int *instance,
unsigned int queue_size);
```
Advertises a topic with both an instance ID and a queue depth.
**Parameters**:
- `meta` Pointer to topic metadata.
- `data` Initial data.
- `instance` Input/output parameter that returns the instance ID.
- `queue_size` Queue depth.
**Returns**:
Returns the file descriptor on success, or a negative value on failure.
### orb_advertise_multi_queue_persist_info
```c
int orb_advertise_multi_queue_persist_info(const struct orb_metadata *meta,
const void *data, int *instance,
unsigned int queue_size,
orb_info_t *info);
```
Advertises a topic with persistent info fields. The `info` parameter is used to pass additional topic metadata.
**Parameters**:
- `meta` Pointer to topic metadata.
- `data` Initial data.
- `instance` Input/output parameter that returns the instance ID.
- `queue_size` Queue depth.
- `info` Pointer to additional topic information.
**Returns**:
Returns the file descriptor on success, or a negative value on failure.
### orb_publish
```c
static inline int orb_publish(const struct orb_metadata *meta, int fd, const void *data);
```
Publishes topic data (default length obtained from meta).
**Parameters**:
- `meta` Pointer to topic metadata.
- `fd` Advertiser file descriptor.
- `data` Data to publish.
**Returns**:
Returns the number of bytes published on success, or a negative value on failure.
### orb_publish_auto
```c
static inline int orb_publish_auto(const struct orb_metadata *meta, int *fd,
const void *data, int *instance);
```
Automatically advertises and publishes. If `*fd` is less than 0, an advertiser is created automatically. Convenient for simple publish scenarios.
**Parameters**:
- `meta` Pointer to topic metadata.
- `fd` Input/output parameter, advertiser file descriptor.
- `data` Data to publish.
- `instance` Input/output parameter that returns the instance ID.
**Returns**:
Returns `0` on success, or a negative value on failure.
## Subscribe Interface
### orb_subscribe_multi
```c
int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance);
```
Subscribes to a topic in non-wakeup mode. After data is published, waiting subscribers are woken up; non-waiting subscribers can use `orb_check` to check for updates.
If the subscription occurs after a publish, calling `orb_check` immediately after a successful subscription will return `true`. Even if the topic has not been advertised yet, the subscription will succeed — in this case the topic timestamp is 0, no poll events are triggered, `orb_check` always returns `false`, and data cannot be copied until the topic is subsequently advertised.
### orb_unsubscribe
```c
static inline int orb_unsubscribe(int fd) { return orb_close(fd);
```
Unsubscribes from a topic.
### orb_copy_multi
```c
ssize_t orb_copy_multi(int fd, void *buffer, size_t len);
```
Retrieves data of a specified length from a topic. This is the **only** interface that resets the "subscriber received new data" flag — once `poll` or `orb_check` indicates an update, this interface must be called to consume the data.
### orb_check
```c
int orb_check(int fd, bool *updated);
```
Checks whether a topic has had new data published since the last `orb_copy`. Used in scenarios that do not use `poll()` to determine whether `orb_copy` needs to be called; also avoids the overhead of calling `poll()` when the topic has very likely been updated. The update state is tracked per fd: after returning `true`, `orb_copy` must be called on the same fd to reset the update flag, otherwise this interface will continue to return `true`.
### orb_subscribe
```c
static inline int orb_subscribe(const struct orb_metadata *meta);
```
Subscribes to the default instance of a topic. Equivalent to `orb_subscribe_multi(meta, 0)`.
**Parameters**:
- `meta` Pointer to topic metadata.
**Returns**:
Returns the subscriber file descriptor on success, or a negative value on failure.
### orb_subscribe_wakeup
```c
static inline int orb_subscribe_wakeup(const struct orb_metadata *meta);
```
Subscribes to the default instance with wakeup mode enabled (asynchronously wakes the caller when new data arrives). Equivalent to `orb_subscribe_multi_wakeup(meta, 0)`.
**Parameters**:
- `meta` Pointer to topic metadata.
**Returns**:
Returns the file descriptor on success, or a negative value on failure.
### orb_subscribe_multi_wakeup
```c
int orb_subscribe_multi_wakeup(const struct orb_metadata *meta, unsigned instance);
```
Subscribes to a topic with a specified instance ID and enables wakeup mode.
**Parameters**:
- `meta` Pointer to topic metadata.
- `instance` Instance ID.
**Returns**:
Returns the file descriptor on success, or a negative value on failure.
### orb_copy
```c
static inline int orb_copy(const struct orb_metadata *meta, int fd, void *buffer);
```
Copies the latest topic data from the subscriber fd to the buffer, using the default length (obtained from meta).
**Parameters**:
- `meta` Pointer to topic metadata.
- `fd` Subscriber file descriptor.
- `buffer` Buffer to receive the data.
**Returns**:
Returns the number of bytes copied on success, or a negative value on failure.
### orb_unlink
```c
static inline int orb_unlink(const struct orb_metadata *meta);
```
Removes the default instance of a topic. Equivalent to `orb_unlink_multi(meta, 0)`.
**Parameters**:
- `meta` Pointer to topic metadata.
**Returns**:
Returns `0` on success, or a negative value on failure.
## Control Interface
### orb_get_state
```c
int orb_get_state(int fd, struct orb_state *state);
```
Retrieves the state information of all subscribers for a topic. The state includes the maximum frequency and minimum batch interval among all subscribers, as well as the `enable` field (indicating whether the current node is subscribed or active). If there are no subscribers, the state fields are set to: `max_frequency=0`, `min_batch_interval=0`, `enable=false`.
### orb_get_events
```c
int orb_get_events(int fd, unsigned int *events);
```
Retrieves event information for the specified subscriber.
### orb_ioctl
```c
int orb_ioctl(int fd, int cmd, unsigned long arg);
```
Performs ioctl control on a subscriber, identical to ioctl().
### orb_flush
```c
int orb_flush(int fd);
```
Flushes accumulated topic data from the hardware buffer. When the hardware FIFO has not reached the watermark but an immediate read is desired, calling this interface forces the FIFO data to be output; there is no restriction on when to call it. After calling, you can monitor the `POLLPRI` event on the fd and use `orb_get_events` to determine whether the flush is complete.
### orb_set_batch_interval
```c
int orb_set_batch_interval(int fd, unsigned batch_interval);
```
Sets the desired batch interval for the user. The actual effective value depends on the hardware FIFO capability. This interface triggers a `POLLPRI` event to notify the publisher, which then decides the final batch interval. Only applicable to topics with hardware FIFO (e.g., sensors with hardware FIFO); otherwise the call has no effect.
### orb_get_batch_interval
```c
int orb_get_batch_interval(int fd, unsigned *batch_interval);
```
Retrieves the currently effective batch interval in batch mode. Only applicable to topics with hardware FIFO (e.g., sensors with hardware FIFO); otherwise the call has no effect. See `orb_set_batch_interval`.
### orb_set_interval
```c
int orb_set_interval(int fd, unsigned interval);
```
Sets the minimum reporting interval for a subscriber (in microseconds).
**Parameters**:
- `fd` Subscriber file descriptor.
- `interval` Reporting interval in microseconds; `0` means no limit.
**Returns**:
Returns `0` on success, or a negative value on failure.
### orb_get_interval
```c
int orb_get_interval(int fd, unsigned *interval);
```
Retrieves the current reporting interval for a subscriber (in microseconds).
**Parameters**:
- `fd` Subscriber file descriptor.
- `interval` Output parameter that returns the current interval value.
**Returns**:
Returns `0` on success, or a negative value on failure.
### orb_set_frequency
```c
static inline int orb_set_frequency(int fd, unsigned frequency);
```
Sets the reporting interval for a subscriber by frequency (Hz). Equivalent to `orb_set_interval(fd, frequency ? 1000000/frequency : 0)`.
**Parameters**:
- `fd` Subscriber file descriptor.
- `frequency` Target frequency (Hz); `0` means no limit.
**Returns**:
Returns `0` on success, or a negative value on failure.
### orb_get_frequency
```c
static inline int orb_get_frequency(int fd, unsigned *frequency);
```
Retrieves the current reporting rate for a subscriber by frequency (Hz).
**Parameters**:
- `fd` Subscriber file descriptor.
- `frequency` Output parameter that returns the current frequency.
**Returns**:
Returns `0` on success, or a negative value on failure.
### orb_get_info
```c
int orb_get_info(int fd, orb_info_t *info);
```
Retrieves topic information.
### orb_info
```c
void orb_info(const char *format, const char *name, const void *data);
```
Prints sensor data.
## Query Interface
### orb_elapsed_time
```c
orb_abstime orb_absolute_time(void);
```
Retrieves the current system time (in microseconds).
### orb_exists
```c
int orb_exists(const struct orb_metadata *meta, int instance);
```
Checks whether a topic instance has been advertised.
### orb_group_count
```c
int orb_group_count(const struct orb_metadata *meta);
```
Retrieves the number of advertised topic instances.
### orb_absolute_time
```c
orb_abstime orb_absolute_time(void);
```
Retrieves a monotonically increasing absolute timestamp (in microseconds), used for timestamping topic data.
**Returns**:
Returns the current timestamp.
### orb_get_meta
```c
const struct orb_metadata *orb_get_meta(const char *name);
```
Retrieves topic metadata by name string.
## Formatted I/O
### orb_sscanf
```c
int orb_sscanf(const char *buf, const char *format, void *data);
```
Converts a string value into a struct buffer.
### orb_fprintf
```c
int orb_fprintf(FILE *stream, const char *format, const void *data);
```
Prints sensor data to a file.
## Event Loop
### orb_loop_init
```c
int orb_loop_init(struct orb_loop_s *loop, enum orb_loop_type_e type);
```
Initializes an orb event loop. Use orb_loop_deinit to release resources.
### orb_loop_run
```c
int orb_loop_run(struct orb_loop_s *loop);
```
Starts the event loop. After the loop starts, users can dynamically add new file descriptors via `orb_handle_start` or close existing ones via `orb_handle_stop`. The loop enters a blocking state after starting.
### orb_loop_deinit
```c
int orb_loop_deinit(struct orb_loop_s *loop);
```
Deinitializes the current event loop. After deinitialization, the loop must be reinitialized before reuse. Handles added to the loop via `orb_handle_init` are the user's responsibility to close.
### orb_loop_exit_async
```c
int orb_loop_exit_async(struct orb_loop_s *loop);
```
Sends an exit event to the current event loop (non-blocking).
### orb_handle_init
```c
int orb_handle_init(struct orb_handle_s *handle, int fd, int events, void *arg, orb_datain_cb_t datain_cb, orb_dataout_cb_t dataout_cb, orb_eventpri_cb_t pri_cb, orb_eventerr_cb_t err_cb);
```
Initializes an orb handle.
### orb_handle_start
```c
int orb_handle_start(struct orb_loop_s *loop, struct orb_handle_s *handle);
```
Starts a handle in the event loop.
### orb_handle_stop
```c
int orb_handle_stop(struct orb_loop_s *loop, struct orb_handle_s *handle);
```
Stops a handle in the event loop.

View File

@ -1,8 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/utils/index.md) \]
# Utils
The openvela utility library provides common development tools including the logging system (ALOG) and performance tracing (ATrace).
- **[Log](log.md)** — ALOG logging system
- **[Trace](trace.md)** — ATrace performance tracing

View File

@ -1,139 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/utils/log.md) \]
# ALOG Introduction
ALOG (Android Log) is a commonly used set of logging macros that provides a simplified way to record log messages. It is a macro wrapper around the `__android_log_print` function, making it more convenient and intuitive to log messages in C or C++ code.
## Data Structure Definitions
### LOG Priority
LOG priority is used to control filtering of different log levels. The default output LOG level can be controlled via `CONFIG_ALOG`:
```c
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0, // Unknown
ANDROID_LOG_DEFAULT, // Default
ANDROID_LOG_VERBOSE, // Verbose
ANDROID_LOG_DEBUG, // Debug
ANDROID_LOG_INFO, // Info
ANDROID_LOG_WARN, // Warning
ANDROID_LOG_ERROR, // Error
ANDROID_LOG_FATAL, // Fatal
ANDROID_LOG_SILENT, // Silent
} android_LogPriority;
```
### LOG ID
LOG ID is used to identify a specific log buffer, used with `__android_log_buf_write()` and `__android_log_buf_print()`.
```c
typedef enum log_id {
LOG_ID_MIN = 0,
LOG_ID_MAIN = 0,
LOG_ID_RADIO = 1,
LOG_ID_EVENTS = 2,
LOG_ID_SYSTEM = 3,
LOG_ID_CRASH = 4,
LOG_ID_STATS = 5,
LOG_ID_SECURITY = 6,
LOG_ID_KERNEL = 7,
LOG_ID_MAX,
LOG_ID_DEFAULT = 0x7FFFFFFF
} log_id_t;
```
## API List
Below are the definitions and parameter descriptions of the raw LOG APIs:
```c
/**
* @brief Write a string to the log system.
*
* @param prio The priority of the log message, using `android_LogPriority` enum values.
* @param tag The tag associated with the log message.
* @param text The constant string to log.
* @return int Returns 0 on success, non-zero on failure.
*/
int __android_log_write(int prio, const char* tag, const char* text);
/**
* @brief Write a formatted log message.
*
* @param prio The priority of the log message, using `android_LogPriority` enum values.
* @param tag The tag associated with the log message.
* @param fmt Format string, followed by a series of arguments.
* @return int Returns 0 on success, non-zero on failure.
*/
int __android_log_print(int prio, const char* tag, const char* fmt, ...);
/**
* @brief Write a formatted log message using a variable argument list.
*
* @param prio The priority of the log message, using `android_LogPriority` enum values.
* @param tag The tag associated with the log message.
* @param fmt Format string.
* @param ap Variable argument list containing all parameters.
* @return int Returns 0 on success, non-zero on failure.
*/
int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap);
/**
* @brief Write an assertion message to the log system when a condition fails.
*
* @param cond String representation of the assertion condition.
* @param tag The tag associated with the log message.
* @param fmt Format string, followed by a series of arguments (optional).
*/
void __android_log_assert(const char* cond, const char* tag, const char* fmt, ...);
```
In addition to the raw APIs, ALOG provides a set of macros for simplified usage:
```c
/**
* @brief Send a log message at the specified level.
*
* @param ... Variable argument list, format and parameters similar to printf.
*/
#define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
/**
* @brief Write a log message when the condition is true.
*
* @param cond The condition to evaluate.
* @param ... Variable argument list, format and parameters similar to printf.
*/
#define ALOGV_IF(cond, ...)
#define ALOGD_IF(cond, ...)
#define ALOGI_IF(cond, ...)
#define ALOGW_IF(cond, ...)
#define ALOGE_IF(cond, ...)
```
## Usage Example
```c
#include <log/log.h>
#define LOG_TAG "MyAppTag"
void log_info_alogi() {
}
int main() {
// Print log with custom priority
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Formatted number: %d", 42);
// Print INFO level log using macro
ALOGI("ALOGI: A log message from my app.");
return 0;
}
```

View File

@ -1,79 +0,0 @@
\[ English | [简体中文](../../../../zh-cn/api/framework/utils/trace.md) \]
# ATrace Introduction
ATrace (Android Trace) provides a set of application-layer Trace APIs. You can use these APIs to instrument your application for performance analysis and optimize execution efficiency.
## API Reference
```c
// Header file
#include <cutils/trace.h>
// Check whether Trace is enabled. Can be used to conditionally execute tracing code to reduce performance overhead in non-tracing mode.
ATRACE_ENABLED()
// Begin tracing a context (typically used for function execution time tracking). The name parameter identifies the context.
ATRACE_BEGIN(name)
// End tracing a context. This call should be paired with a corresponding ATRACE_BEGIN and executed after it.
ATRACE_END()
// Begin tracing an asynchronous event. Unlike ATRACE_BEGIN/ATRACE_END, asynchronous events do not need to be nested.
// name describes the event, while cookie provides a unique identifier to distinguish simultaneous events.
// The name and cookie used when starting and ending the event must be consistent.
ATRACE_ASYNC_BEGIN(name, cookie)
// End tracing an asynchronous event. This call should have a corresponding ATRACE_ASYNC_BEGIN.
ATRACE_ASYNC_END(name, cookie)
// Begin tracing an asynchronous event. In addition to name and cookie, a track_name parameter specifies
// the name of the track where this asynchronous event should be recorded.
// The track_name, name, and cookie used when starting the event must match those used when ending it.
ATRACE_ASYNC_FOR_TRACK_BEGIN(track_name, name, cookie)
// End tracing an asynchronous event. This call should correspond to a previous ATRACE_ASYNC_FOR_TRACK_BEGIN.
ATRACE_ASYNC_FOR_TRACK_END(track_name, cookie)
// Trace an instant context. name identifies the context.
// An instant event is an event with no defined duration, visualized as a single marker on the timeline.
ATRACE_INSTANT(name)
// Trace an instant context with a specified track name for recording the event.
// Similar to ATRACE_INSTANT, but allows placing different instant events into the same timeline track/row.
ATRACE_INSTANT_FOR_TRACK(name, track_name)
// Trace an integer counter value. name identifies the counter. This can be used to track values that change over time.
ATRACE_INT(name, value)
// Trace a 64-bit integer counter value. Used the same way as ATRACE_INT, but for larger value ranges.
ATRACE_INT64(name, value)
```
## Usage Example
```c
#define ATRACE_TAG ATRACE_TAG_ALWAYS
#include <cutils/trace.h>
int main(int argc, char *argv[])
{
// Instrument the current function
ATRACE_BEGIN("hello_main");
sleep(1);
ATRACE_INSTANT("printf");
printf("hello world!");
// End instrumentation
ATRACE_END();
return 0;
}
```
The trace dump command output looks like:
```
hello-7 [0] 3.187400000: sched_wakeup_new: comm=hello pid=7 target_cpu=0
hello-7 [0] 3.187400000: tracing_mark_write: B|7|hello_main
hello-7 [0] 4.197700000: tracing_mark_write: I|7|printf
hello-7 [0] 4.187700000: tracing_mark_write: E|7|hello_main
```

View File

@ -1,11 +0,0 @@
\[ English | [简体中文](../../zh-cn/api/index.md) \]
# API Reference
This document provides the API reference for the openvela operating system, covering the complete interface specification from kernel system calls to application frameworks.
openvela is built on Apache NuttX RTOS, follows the POSIX standard, and supports multiple architectures including ARM, ARM64, RISC-V, and x86_64. Developers can refer to the following sections for APIs at each layer:
- **[Kernel Interfaces](kernel/index.md)** — POSIX-compatible system interfaces for process/thread management, task scheduling, memory management, signal mechanisms, message queues, etc.
- **[Network Interfaces](network/index.md)** — Standard network programming interfaces including BSD sockets, DNS resolution, etc.
- **[Application Framework](framework/index.md)** — Upper-layer capability interfaces including Binder IPC, Bluetooth, multimedia, security (TEE + Keystore), uORB message bus, etc.

View File

@ -1,11 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/kernel/index.md) \]
# Kernel API
The openvela kernel is based on Apache NuttX RTOS and provides POSIX-compliant system interfaces covering process/thread management, task scheduling, memory management, signal mechanisms, message queues, and other core functionalities. This section provides detailed API references and usage instructions for each kernel subsystem.
- **[Thread Management](thread.md)** — POSIX Thread (pthread) interfaces
- **[Task Scheduling](sched.md)** — Scheduling policies, priorities, task attributes
- **[Memory Management](mem.md)** — Heap memory allocation, memory pools, memory information queries
- **[Signal Mechanism](signal.md)** — POSIX signals, signal handling, signal sets
- **[Message Queue](msgqueue.md)** — POSIX message queues

File diff suppressed because it is too large Load Diff

View File

@ -1,305 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/kernel/msgqueue.md) \]
# Message Queue API
openvela provides POSIX-compliant message queue interfaces for asynchronous message passing between tasks. Message queues support priority ordering, where higher-priority messages are received first.
Header file: `#include <mqueue.h>`
## openvela Implementation Notes
- **Sending from interrupts**: `mq_send()` can be called from interrupt context, but behaves differently: it does not check queue size, uses pre-allocated messages (quantity configured by `PREALLOC_MQ_IRQ_MSGS`)
- **Notification behavior difference**: `mq_notify()` sends the notification signal even when a task is waiting to receive a message, which is not fully consistent with the POSIX specification
- **Timeout values**: `mq_timedsend()` and `mq_timedreceive()` use Epoch-based absolute time
## Queue Management
### mq_open
```c
mqd_t mq_open(const char *mqName, int oflags, ...);
```
Establishes a connection between the calling task and a message queue. After a successful call, the returned message queue descriptor can be used for subsequent operations until `mq_close()` is called.
**Parameters**:
- `mqName` Name of the message queue.
- `oflags` Open flags, which can be any combination of:
- `O_RDONLY` Read-only.
- `O_WRONLY` Write-only.
- `O_RDWR` Read-write.
- `O_CREAT` Create the message queue if it does not exist.
- `O_EXCL` Used with `O_CREAT`, fails if the queue already exists.
- `O_NONBLOCK` Non-blocking mode.
- `...` Optional arguments required when `O_CREAT` is used:
- `mode` (`mode_t`) File permission bits. Not used in the current implementation, but required by POSIX.
- `attr` (`struct mq_attr *`) Queue attributes. If `NULL`, default values are used. `mq_maxmsg` sets the maximum number of messages, `mq_msgsize` sets the maximum message size.
**Returns**:
Returns a message queue descriptor (`mqd_t`) on success, or -1 (`ERROR`) on failure and sets `errno`:
- `ENOENT` `O_CREAT` was not set and the specified queue does not exist.
- `EEXIST` Both `O_CREAT` and `O_EXCL` were set, but the queue already exists.
- `EINVAL` Invalid argument (e.g., `mqName` is `NULL`).
- `ENOMEM` Insufficient memory to create the queue.
- `ENFILE` System message queue limit reached.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
### mq_close
```c
int mq_close(mqd_t mqdes);
```
Closes a message queue descriptor, releasing system resources allocated to the task. If the task has registered a notification request on this queue, the notification is cancelled.
**Parameters**:
- `mqdes` Message queue descriptor.
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EBADF` `mqdes` is not a valid message queue descriptor.
**Notes**:
- Calling `mq_close()` while `mq_send()` or `mq_receive()` is blocked is undefined behavior.
- Using the same `mqdes` after closing is undefined behavior.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
### mq_unlink
```c
int mq_unlink(const char *mqName);
```
Removes the named message queue. If any tasks still have the queue open, the removal is deferred until all descriptors are closed.
**Parameters**:
- `mqName` Name of the message queue.
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `ENOENT` The specified queue does not exist.
- `EINVAL` `mqName` is `NULL`.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
## Sending Messages
### mq_send
```c
int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio);
```
Sends a message to a message queue. Messages are ordered by priority, with higher-priority messages placed before lower-priority ones. `prio` must not exceed `MQ_PRIO_MAX`.
If the queue is full and `O_NONBLOCK` is not set, the call blocks until space becomes available. If `O_NONBLOCK` is set, it returns an error immediately.
**Parameters**:
- `mqdes` Message queue descriptor.
- `msg` Message to send.
- `msglen` Length of the message in bytes, must not exceed `mq_msgsize`.
- `prio` Message priority.
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EAGAIN` Queue is full and `O_NONBLOCK` is set.
- `EINVAL` `msg` or `mqdes` is `NULL`, or `prio` is invalid.
- `EPERM` Message queue was not opened for writing.
- `EMSGSIZE` `msglen` exceeds the queue's `mq_msgsize`.
- `EINTR` Interrupted by a signal.
**Notes**:
- `mq_send()` can be called from interrupt context, but behaves differently: it does not check queue size (always sends), uses pre-allocated messages (quantity configured by `PREALLOC_MQ_IRQ_MSGS`), and does not allocate new memory.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
### mq_timedsend
```c
int mq_timedsend(mqd_t mqdes, const void *msg, size_t msglen, int prio,
const struct timespec *abstime);
```
Sends a message with a timeout. Behaves the same as `mq_send()`, but when the queue is full, blocks at most until the absolute time specified by `abstime`.
**Parameters**:
- `mqdes` Message queue descriptor.
- `msg` Message to send.
- `msglen` Length of the message in bytes.
- `prio` Message priority.
- `abstime` Absolute timeout (Epoch-based).
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EAGAIN` Queue is full and `O_NONBLOCK` is set.
- `EINVAL` `msg` or `mqdes` is `NULL`, or `prio` is invalid.
- `EPERM` Message queue was not opened for writing.
- `EMSGSIZE` `msglen` exceeds the queue's `mq_msgsize`.
- `EINTR` Interrupted by a signal.
- `ETIMEDOUT` Timed out.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
## Receiving Messages
### mq_receive
```c
ssize_t mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio);
```
Receives the oldest message with the highest priority from the message queue. `msglen` must not be less than the queue's `mq_msgsize`, otherwise an error is returned.
If the queue is empty and `O_NONBLOCK` is not set, the call blocks until a message is available. Among multiple waiting tasks, the one with the highest priority and longest wait time receives first.
**Parameters**:
- `mqdes` Message queue descriptor.
- `msg` Buffer to receive the message.
- `msglen` Buffer size in bytes.
- `prio` If not `NULL`, stores the priority of the received message.
**Returns**:
Returns the message length in bytes on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EAGAIN` Queue is empty and `O_NONBLOCK` is set.
- `EPERM` Message queue was not opened for reading.
- `EMSGSIZE` `msglen` is less than the queue's `mq_msgsize`.
- `EINTR` Interrupted by a signal.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
### mq_timedreceive
```c
ssize_t mq_timedreceive(mqd_t mqdes, char *msg, size_t msglen,
unsigned int *prio, const struct timespec *abstime);
```
Receives a message with a timeout. Behaves the same as `mq_receive()`, but when the queue is empty, blocks at most until the absolute time specified by `abstime`.
**Parameters**:
- `mqdes` Message queue descriptor.
- `msg` Buffer to receive the message.
- `msglen` Buffer size in bytes.
- `prio` If not `NULL`, stores the priority of the received message.
- `abstime` Absolute timeout (Epoch-based).
**Returns**:
Returns the message length in bytes on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EAGAIN` Queue is empty and `O_NONBLOCK` is set.
- `EPERM` Message queue was not opened for reading.
- `EMSGSIZE` `msglen` is less than the queue's `mq_msgsize`.
- `EINTR` Interrupted by a signal.
- `ETIMEDOUT` Timed out.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
## Queue Attributes
### mq_setattr
```c
int mq_setattr(mqd_t mqdes, const struct mq_attr *mqStat, struct mq_attr *oldMqStat);
```
Sets message queue attributes. Only the `O_NONBLOCK` bit in `mq_flags` can be modified.
**Parameters**:
- `mqdes` Message queue descriptor.
- `mqStat` New attributes.
- `oldMqStat` If not `NULL`, stores the attributes before modification.
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EBADF` `mqdes` is not a valid descriptor.
- `EINVAL` `mqStat` is `NULL`.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
### mq_getattr
```c
int mq_getattr(mqd_t mqdes, struct mq_attr *mqStat);
```
Gets the current attributes of a message queue.
**Parameters**:
- `mqdes` Message queue descriptor.
- `mqStat` Returns the attribute structure:
- `mq_maxmsg` Maximum number of messages in the queue.
- `mq_msgsize` Maximum message size in bytes.
- `mq_flags` Message queue flags.
- `mq_curmsgs` Current number of messages in the queue.
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EBADF` `mqdes` is not a valid descriptor.
- `EINVAL` `mqStat` is `NULL`.
**POSIX Compatibility**: Compatible with the POSIX interface of the same name.
## Notification
### mq_notify
```c
int mq_notify(mqd_t mqdes, const struct sigevent *notification);
```
Registers or cancels message arrival notification. When a message arrives at a previously empty queue, a signal notification is sent to the registered task.
If `notification` is `NULL`, the current registration is cancelled. The registration is automatically cancelled after the notification is sent and must be re-registered.
**Parameters**:
- `mqdes` Message queue descriptor.
- `notification` Notification configuration, including:
- `sigev_notify` Notification method (should be `SIGEV_SIGNAL`).
- `sigev_signo` Signal number for notification.
- `sigev_value` Value passed with the signal.
**Returns**:
Returns 0 on success, or -1 (`ERROR`) on failure and sets `errno`:
- `EBADF` `mqdes` is not a valid descriptor.
- `EBUSY` Another task has already registered notification for this queue.
- `EINVAL` `sigev_notify` is not a valid value, or the signal number is invalid.
- `ENOMEM` Insufficient memory.
**Notes**:
- **Behavior difference from POSIX**: In openvela, the notification signal is still sent to the registered task even when a task is blocked on `mq_receive()` waiting for a message. The POSIX specification requires that no notification be sent in this case (the message directly satisfies the waiting `mq_receive()`).
**POSIX Compatibility**: Partially compatible with the POSIX interface of the same name (notification timing differs from the POSIX specification).

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/network/index.md) \]
# Network Interface
openvela includes a comprehensive network subsystem that provides standard BSD socket interfaces and DNS resolution capabilities. The network subsystem is optional and can be configured according to application requirements. The network interfaces provided by openvela follow the POSIX standard, making it easy to port existing network applications to openvela.
## Core Interfaces
- **[Network Interface](net.md)** — BSD socket interface (socket/bind/connect/send/recv) and DNS resolution
## Address Management and Configuration
- **[DHCP](net_dhcp.md)** — DHCP client (IPv4), DHCPv6 client, and DHCP server
- **[Network Utility Library netlib](netlib.md)** — IPv4/IPv6 address, routing, MAC, MTU, iptables, connectivity check, and other utility interfaces
## Wireless Networking
- **[WAPI Wireless Interface](wapi.md)** — Wi-Fi interface configuration, scanning, association, and power management (based on Linux Wireless Extensions)
## File Services
- **[FTP Server](net_ftp.md)** — Lightweight FTP server interface

View File

@ -1,591 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/network/net.md) \]
# Network API
openvela provides BSD-compatible socket interfaces, supporting protocol families such as IPv4 (`AF_INET`), IPv6 (`AF_INET6`), as well as stream sockets (`SOCK_STREAM`), datagram sockets (`SOCK_DGRAM`), and raw sockets (`SOCK_RAW`).
Header files: `#include <sys/socket.h>`, `#include <netinet/in.h>`, `#include <arpa/inet.h>`
## openvela Implementation Notes
- **Protocol family support**: `AF_INET` (IPv4), `AF_INET6` (IPv6), `AF_LOCAL`/`AF_UNIX` (local sockets), `AF_PACKET` (raw link layer), etc., depending on network stack configuration
- **Configuration dependency**: The network subsystem is optional and requires enabling `CONFIG_NET` and related protocol configurations (e.g., `CONFIG_NET_TCP`, `CONFIG_NET_UDP`)
- **Non-blocking I/O**: Set via `fcntl(fd, F_SETFL, O_NONBLOCK)` or the `SOCK_NONBLOCK` flag
- **DNS resolution**: Requires enabling `CONFIG_NETDB_DNSCLIENT`, DNS servers are managed through the `nuttx/net/dns.h` interface
## Socket Creation and Management
### socket
```c
int socket(int domain, int type, int protocol);
```
Creates a communication endpoint (socket) and returns a file descriptor.
**Parameters**:
- `domain` Protocol family:
- `AF_INET` IPv4
- `AF_INET6` IPv6
- `AF_LOCAL` / `AF_UNIX` Local socket
- `AF_PACKET` Raw link layer
- `type` Socket type:
- `SOCK_STREAM` Connection-oriented stream socket (TCP)
- `SOCK_DGRAM` Connectionless datagram socket (UDP)
- `SOCK_RAW` Raw socket
- Can be bitwise OR'd with `SOCK_NONBLOCK`, `SOCK_CLOEXEC`
- `protocol` Protocol number, usually 0 (auto-select). Can also specify `IPPROTO_TCP`, `IPPROTO_UDP`, etc.
**Returns**:
Returns a non-negative file descriptor on success, or -1 on failure and sets `errno`:
- `EAFNOSUPPORT` Unsupported protocol family.
- `EPROTONOSUPPORT` Unsupported protocol type.
- `EMFILE` Process file descriptor limit reached.
- `ENOMEM` Insufficient memory.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### socketpair
```c
int socketpair(int domain, int type, int protocol, int sv[2]);
```
Creates a pair of connected sockets, commonly used for inter-process communication between parent and child processes.
**Parameters**:
- `domain` Protocol family, usually `AF_LOCAL`.
- `type` Socket type (`SOCK_STREAM` or `SOCK_DGRAM`).
- `protocol` Usually 0.
- `sv` Output parameter, stores two connected file descriptors.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EAFNOSUPPORT` Unsupported protocol family.
- `EMFILE` File descriptor limit reached.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### shutdown
```c
int shutdown(int sockfd, int how);
```
Shuts down part or all communication directions of a socket. Unlike `close()`, `shutdown()` can close only the read or write direction.
**Parameters**:
- `sockfd` Socket file descriptor.
- `how` Shutdown mode:
- `SHUT_RD` Close the read direction.
- `SHUT_WR` Close the write direction (sends FIN).
- `SHUT_RDWR` Close both read and write directions.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `ENOTCONN` Socket is not connected.
- `EINVAL` Invalid `how` parameter.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
## Connection Management
### bind
```c
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
```
Binds a socket to a specified local address and port. The server side must call `bind()` before `listen()`.
**Parameters**:
- `sockfd` Socket file descriptor.
- `addr` Local address structure (`struct sockaddr_in` or `struct sockaddr_in6`).
- `addrlen` Size of the address structure.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `EINVAL` Socket is already bound, or address is invalid.
- `EADDRINUSE` Address already in use.
- `EADDRNOTAVAIL` Requested address is not available.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### connect
```c
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
```
Initiates a connection to a remote address. For TCP sockets, performs the three-way handshake; for UDP sockets, sets the default destination address.
**Parameters**:
- `sockfd` Socket file descriptor.
- `addr` Remote address structure.
- `addrlen` Size of the address structure.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `ECONNREFUSED` Remote host refused the connection.
- `ETIMEDOUT` Connection timed out.
- `ENETUNREACH` Network is unreachable.
- `EINPROGRESS` Connection is in progress in non-blocking mode.
- `EISCONN` Socket is already connected.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### listen
```c
int listen(int sockfd, int backlog);
```
Marks a socket as a passive listening socket, ready to accept connection requests.
**Parameters**:
- `sockfd` Bound socket file descriptor.
- `backlog` Maximum length of the pending connection queue.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `EOPNOTSUPP` Socket type does not support `listen()`.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### accept
```c
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
```
Extracts the first connection request from the listening socket's pending queue, creates and returns a new connected socket. Blocks if the queue is empty.
**Parameters**:
- `sockfd` Listening socket file descriptor.
- `addr` If non-`NULL`, stores the client address.
- `addrlen` On input, the size of the `addr` buffer; on output, the actual address size.
**Returns**:
Returns a new connected socket descriptor on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `EMFILE` File descriptor limit reached.
- `ECONNABORTED` Connection was aborted.
- `EINTR` Interrupted by a signal.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### accept4
```c
int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
```
Same as `accept()`, but allows setting attributes on the new socket via `flags`.
**Parameters**:
- `sockfd` Listening socket file descriptor.
- `addr` Client address (can be `NULL`).
- `addrlen` Address length.
- `flags` Flags:
- `SOCK_NONBLOCK` Set the new socket to non-blocking.
- `SOCK_CLOEXEC` Set the new socket to close-on-exec.
**Returns**:
Same as `accept()`.
**POSIX Compatibility**: Compatible with Linux extension (non-POSIX).
## Data Sending
### send
```c
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
```
Sends data on a connected socket. Equivalent to `sendto()` without specifying a destination address.
**Parameters**:
- `sockfd` Connected socket file descriptor.
- `buf` Data buffer to send.
- `len` Data length (bytes).
- `flags` Send flags:
- `MSG_DONTWAIT` Non-blocking send.
- `MSG_NOSIGNAL` Do not generate `SIGPIPE` when the peer closes.
- `0` Default behavior.
**Returns**:
Returns the number of bytes sent on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `ENOTCONN` Socket is not connected.
- `EAGAIN` / `EWOULDBLOCK` Send buffer is full in non-blocking mode.
- `EPIPE` Peer has closed the connection.
- `EINTR` Interrupted by a signal.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### sendto
```c
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *to, socklen_t tolen);
```
Sends data to a specified address. Primarily used for UDP sockets; can also be used on connected TCP sockets (destination address is ignored in that case).
**Parameters**:
- `sockfd` Socket file descriptor.
- `buf` Data buffer.
- `len` Data length.
- `flags` Send flags (same as `send()`).
- `to` Destination address. Can be `NULL` for connected sockets.
- `tolen` Destination address length.
**Returns**:
Returns the number of bytes sent on success, or -1 on failure and sets `errno` (same as `send()`, plus):
- `EDESTADDRREQ` Unconnected socket and no destination address specified.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### sendmsg
```c
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
```
Sends data via an `msghdr` structure, supporting scatter/gather I/O and ancillary data (e.g., file descriptor passing).
**Parameters**:
- `sockfd` Socket file descriptor.
- `msg` Message header structure containing destination address, I/O vectors, ancillary data, etc.
- `flags` Send flags.
**Returns**:
Returns the number of bytes sent on success, or -1 on failure and sets `errno`.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
## Data Receiving
### recv
```c
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
```
Receives data from a connected socket.
**Parameters**:
- `sockfd` Connected socket file descriptor.
- `buf` Receive buffer.
- `len` Buffer size (bytes).
- `flags` Receive flags:
- `MSG_DONTWAIT` Non-blocking receive.
- `MSG_PEEK` Peek at data without removing it.
- `MSG_WAITALL` Wait to receive the full `len` bytes.
- `0` Default behavior.
**Returns**:
Returns the number of bytes received on success (0 indicates the peer closed the connection), or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `ENOTCONN` Socket is not connected.
- `EAGAIN` / `EWOULDBLOCK` No data available in non-blocking mode.
- `EINTR` Interrupted by a signal.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### recvfrom
```c
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen);
```
Receives data and obtains the sender's address. Primarily used for UDP sockets.
**Parameters**:
- `sockfd` Socket file descriptor.
- `buf` Receive buffer.
- `len` Buffer size.
- `flags` Receive flags (same as `recv()`).
- `from` If non-`NULL`, stores the sender's address.
- `fromlen` On input, the size of the `from` buffer; on output, the actual address size.
**Returns**:
Returns the number of bytes received on success, or -1 on failure and sets `errno` (same as `recv()`).
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### recvmsg
```c
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
```
Receives data via an `msghdr` structure, supporting scatter/gather I/O and ancillary data.
**Parameters**:
- `sockfd` Socket file descriptor.
- `msg` Message header structure.
- `flags` Receive flags.
**Returns**:
Returns the number of bytes received on success, or -1 on failure and sets `errno`.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
## Socket Options
### setsockopt
```c
int setsockopt(int sockfd, int level, int option, const void *value, socklen_t value_len);
```
Sets socket options.
**Parameters**:
- `sockfd` Socket file descriptor.
- `level` Protocol layer of the option:
- `SOL_SOCKET` Socket-level options.
- `IPPROTO_TCP` TCP-level options.
- `IPPROTO_IP` IP-level options.
- `IPPROTO_IPV6` IPv6-level options.
- `option` Option name (e.g., `SO_REUSEADDR`, `SO_KEEPALIVE`, `TCP_NODELAY`, etc.).
- `value` Option value.
- `value_len` Size of the option value.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `ENOPROTOOPT` Unsupported option.
- `EINVAL` Invalid option value.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### getsockopt
```c
int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_len);
```
Gets socket options.
**Parameters**:
- `sockfd` Socket file descriptor.
- `level` Protocol layer (same as `setsockopt()`).
- `option` Option name.
- `value` Buffer to store the option value.
- `value_len` On input, the buffer size; on output, the actual value size.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno` (same as `setsockopt()`).
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
## Address Query
### getsockname
```c
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
```
Gets the local address bound to a socket.
**Parameters**:
- `sockfd` Socket file descriptor.
- `addr` Buffer to store the local address.
- `addrlen` On input, the buffer size; on output, the actual address size.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `EINVAL` Invalid `addrlen`.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
### getpeername
```c
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
```
Gets the remote address of a connected socket.
**Parameters**:
- `sockfd` Connected socket file descriptor.
- `addr` Buffer to store the remote address.
- `addrlen` On input, the buffer size; on output, the actual address size.
**Returns**:
Returns 0 on success, or -1 on failure and sets `errno`:
- `EBADF` Invalid file descriptor.
- `ENOTCONN` Socket is not connected.
**POSIX Compatibility**: Compatible with the POSIX/BSD interface of the same name.
## DNS Interface
Header file: `#include <nuttx/net/dns.h>`
### dns_add_nameserver
```c
int dns_add_nameserver(const struct sockaddr *addr, socklen_t addrlen);
```
Adds a DNS name server.
**Parameters**:
- `addr` DNS server address (`struct sockaddr_in` or `struct sockaddr_in6`).
- `addrlen` Size of the address structure.
**Returns**:
Returns 0 on success, or a negative error code on failure.
**POSIX Compatibility**: openvela/NuttX extension.
### dns_default_nameserver
```c
int dns_default_nameserver(void);
```
Resets the DNS resolver to use only the default DNS server.
**Returns**:
Returns 0 on success, or a negative error code on failure.
**POSIX Compatibility**: openvela/NuttX extension.
### dns_foreach_nameserver
```c
int dns_foreach_nameserver(dns_callback_t callback, void *arg);
```
Iterates over all configured DNS servers, calling the callback function for each server.
**Parameters**:
- `callback` Callback function, called for each DNS server.
- `arg` User argument passed to the callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
**POSIX Compatibility**: openvela/NuttX extension.
### dns_register_notify
```c
int dns_register_notify(dns_callback_t callback, void *arg);
```
Registers a DNS server change notification. The callback function is called when the DNS server list changes.
**Parameters**:
- `callback` Change notification callback function.
- `arg` User argument passed to the callback function.
**Returns**:
Returns 0 on success, or a negative error code on failure.
**POSIX Compatibility**: openvela/NuttX extension.
### dns_unregister_notify
```c
int dns_unregister_notify(dns_callback_t callback, void *arg);
```
Unregisters a DNS server change notification.
**Parameters**:
- `callback` Previously registered callback function.
- `arg` User argument provided during registration.
**Returns**:
Returns 0 on success, or a negative error code on failure.
**POSIX Compatibility**: openvela/NuttX extension.
### dns_set_queryfamily
```c
int dns_set_queryfamily(sa_family_t family);
```
Sets the address family used for DNS queries.
**Parameters**:
- `family` Address family (`AF_INET`, `AF_INET6`, or `AF_UNSPEC`).
**Returns**:
Returns 0 on success, or a negative error code on failure.
**POSIX Compatibility**: openvela/NuttX extension.

View File

@ -1,237 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/network/net_dhcp.md) \]
# DHCP API
DHCP (Dynamic Host Configuration Protocol) client and server interfaces, covering both IPv4 (`dhcpc_*` / `dhcpd_*`) and IPv6 (`dhcp6c_*`) address allocation protocols.
Header files: `#include <netutils/dhcpc.h>`, `#include <netutils/dhcp6c.h>`, `#include <netutils/dhcpd.h>`
## openvela Implementation Notes
- **IPv4 client**: The `dhcpc_*` series encapsulates the complete DHCP client state machine (DISCOVER/OFFER/REQUEST/ACK)
- **IPv6 client**: The `dhcp6c_*` series implements the DHCPv6 client protocol
- **Server**: The `dhcpd_*` series provides simple DHCP server capabilities for IP allocation in hotspot/AP mode
- **Asynchronous calls**: The `*_request_async` interfaces provide callback-based invocation to avoid blocking the current thread
- **Configuration dependency**: Requires enabling `CONFIG_NETUTILS_DHCPC` / `CONFIG_NETUTILS_DHCP6C` / `CONFIG_NETUTILS_DHCPD`
## DHCP Client
Header file: `#include <netutils/dhcpc.h>`
### dhcpc_open
```c
void *dhcpc_open(const char *interface, const void *mac_addr, int mac_len);
```
Creates a DHCP client session.
**Parameters**:
- `interface` Network interface name (e.g., `"eth0"`).
- `mac_addr` MAC address.
- `mac_len` MAC address length.
**Returns**:
Returns a session handle on success, or `NULL` on failure.
### dhcpc_request
```c
int dhcpc_request(void *handle, struct dhcpc_state *presult);
```
Performs DHCP negotiation to obtain an IP address (blocking call).
**Parameters**:
- `handle` Session handle returned by `dhcpc_open()`.
- `presult` Stores the obtained network configuration (IP, subnet mask, gateway, DNS, lease time).
**Returns**:
Returns 0 on success, or -1 on failure.
### dhcpc_request_async
```c
int dhcpc_request_async(void *handle, dhcpc_callback_t callback);
```
Asynchronously performs DHCP negotiation, running in a background thread and returning results via callback.
**Parameters**:
- `handle` Session handle.
- `callback` Result callback function.
**Returns**:
Returns 0 on successful start, or -1 on failure.
### dhcpc_cancel
```c
void dhcpc_cancel(void *handle);
```
Cancels an ongoing DHCP negotiation.
### dhcpc_close
```c
void dhcpc_close(void *handle);
```
Closes the DHCP client session and releases all resources. Internally calls `dhcpc_cancel()` first.
## DHCPv6 Client
Header file: `#include <netutils/dhcp6c.h>`
### dhcp6c_open
```c
void *dhcp6c_open(const char *interface);
```
Creates a DHCPv6 client session.
**Parameters**:
- `interface` Network interface name.
**Returns**:
Returns a session handle on success, or `NULL` on failure.
### dhcp6c_request
```c
int dhcp6c_request(void *handle, struct dhcp6c_state *presult);
```
Performs DHCPv6 negotiation to obtain an address (blocking call).
### dhcp6c_request_async
```c
int dhcp6c_request_async(void *handle, dhcp6c_callback_t callback);
```
Asynchronously performs DHCPv6 negotiation.
### dhcp6c_cancel
```c
void dhcp6c_cancel(void *handle);
```
Cancels an ongoing DHCPv6 negotiation.
### dhcp6c_close
```c
void dhcp6c_close(void *handle);
```
Closes the DHCPv6 client session.
## DHCP Server
Header file: `#include <netutils/dhcpd.h>`
### dhcpd_run
```c
int dhcpd_run(const char *interface);
```
Runs the DHCP server on the current thread (blocking, returns only on error).
### dhcpd_start
```c
int dhcpd_start(const char *interface);
```
Starts the DHCP server daemon as a background task.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### dhcpd_stop
```c
int dhcpd_stop(void);
```
Stops the running DHCP server daemon.
### dhcpd_set_startip
```c
int dhcpd_set_startip(in_addr_t startip);
```
Configures the starting IP address of the DHCP server address pool.
**Parameters**:
- `startip` Starting IP address (network byte order).
**Returns**:
Always returns `0`.
### dhcpd_set_routerip
```c
int dhcpd_set_routerip(in_addr_t routerip);
```
Configures the default gateway address distributed by the DHCP server to clients.
**Parameters**:
- `routerip` Default gateway IP (network byte order).
**Returns**:
Always returns `0`.
### dhcpd_set_netmask
```c
int dhcpd_set_netmask(in_addr_t netmask);
```
Configures the subnet mask distributed by the DHCP server to clients.
**Parameters**:
- `netmask` Subnet mask (network byte order).
**Returns**:
Always returns `0`.
### dhcpd_set_dnsip
```c
int dhcpd_set_dnsip(in_addr_t dnsip);
```
Configures the DNS server address distributed by the DHCP server to clients.
**Parameters**:
- `dnsip` DNS server IP (network byte order).
**Returns**:
Always returns `0`.

View File

@ -1,73 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/network/net_ftp.md) \]
# FTP Server API
A simple FTP server interface providing user management and session handling capabilities.
Header file: `#include <netutils/ftpd.h>`
## openvela Implementation Notes
- **Use cases**: IoT device debugging, firmware upload, file download, and other lightweight FTP applications
- **Configuration dependency**: Requires enabling `CONFIG_NETUTILS_FTPD`
- **User management**: Users and permissions are added via `ftpd_adduser`
- **Session model**: `ftpd_session` provides session handling for a single client connection, typically called in a dedicated thread
## FTP Server
Header file: `#include <netutils/ftpd.h>`
### ftpd_open
```c
FTPD_SESSION ftpd_open(int port, sa_family_t family);
```
Creates an FTP server session.
**Parameters**:
- `port` Listening port (usually 21).
- `family` Address family (`AF_INET` or `AF_INET6`).
**Returns**:
Returns a session handle on success.
### ftpd_adduser
```c
int ftpd_adduser(FTPD_SESSION handle, uint8_t accountflags,
const char *user, const char *passwd, const char *home);
```
Adds an FTP user.
**Parameters**:
- `handle` Handle returned by `ftpd_open()`.
- `accountflags` User attribute flags (see `FTPD_ACCOUNTFLAGS_*`).
- `user` Username (`NULL` means no login required).
- `passwd` Password (`NULL` means no password required).
- `home` User home directory.
### ftpd_session
```c
int ftpd_session(FTPD_SESSION handle, int timeout);
```
Runs an FTP server session, waiting for and handling a single client connection.
**Parameters**:
- `handle` Session handle.
- `timeout` Timeout for waiting for a connection (milliseconds), 0 means wait indefinitely.
### ftpd_close
```c
void ftpd_close(FTPD_SESSION handle);
```
Closes the FTP server session.

View File

@ -1,978 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/network/netlib.md) \]
# Network Utility Library (netlib) API
The openvela network utility library (`netlib_*`) provides a series of helper functions that simplify BSD socket operations, covering IPv4/IPv6 address management, routing, ARP, MAC addresses, MTU, firewall (iptables/ip6tables), network connectivity checks, and more.
Header: `#include <netutils/netlib.h>`
## openvela Implementation Notes
- **Purpose**: Convenience wrappers on top of the BSD socket API, hiding low-level details such as `ioctl` + `SIOCGIF*`
- **Coverage**:
- IPv4/IPv6 addresses, gateways, subnet masks, DNS, routes
- MAC address read/write, interface up/down, MTU setting
- VLAN management, ARP table operations
- iptables/ip6tables operations
- Network connectivity checks (`ping` / HTTP / interface reachability)
- URL parsing utilities
- **Configuration dependencies**: Requires `CONFIG_NETUTILS_NETLIB` to be enabled; some sub-interfaces additionally require the corresponding module configuration (such as `CONFIG_NET_ARP`, `CONFIG_NET_IPv6`, etc.)
- **Error handling**: Most interfaces return `0` or `OK` on success, or `ERROR` (`-1`) with `errno` set on failure
## Network Utility Library
Header: `#include <netutils/netlib.h>`
netlib provides network configuration utility functions, including interface address setting, route management, ARP operations, and more.
**IPv4 Address Management**
### netlib_get_ipv4addr
```c
int netlib_get_ipv4addr(const char *ifname, struct in_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Used to store the IP address.
### netlib_set_ipv4addr
```c
int netlib_set_ipv4addr(const char *ifname, const struct in_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to set.
### netlib_set_dripv4addr
```c
int netlib_set_dripv4addr(const char *ifname, const struct in_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to set.
### netlib_get_dripv4addr
```c
int netlib_get_dripv4addr(const char *ifname, struct in_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Used to store the default route address.
### netlib_set_ipv4netmask
```c
int netlib_set_ipv4netmask(const char *ifname, const struct in_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to set.
### netlib_get_ipv4netmask
```c
int netlib_get_ipv4netmask(const char *ifname, struct in_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Used to store the subnet mask.
### netlib_ipv4adaptor
```c
int netlib_ipv4adaptor(in_addr_t destipaddr, in_addr_t *srcipaddr);
```
**Parameters**:
- `destipaddr` Target IPv4 address.
- `srcipaddr` Used to store the adapter address.
### netlib_read_ipv4route
```c
ssize_t netlib_read_ipv4route(FILE *stream, struct netlib_ipv4_route_s *route);
```
**Parameters**:
- `fd` File descriptor for the procfs IPv4 routing table.
- `route` Used to store the next routing entry.
### netlib_ipv4router
```c
int netlib_ipv4router(const struct in_addr *destipaddr, struct in_addr *router);
```
**Parameters**:
- `destipaddr` Target IP address.
- `router` Used to store the IP address of the gateway router.
### netlib_obtain_ipv4addr
```c
int netlib_obtain_ipv4addr(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
### netlib_set_ipv4dnsaddr
```c
int netlib_set_ipv4dnsaddr(const struct in_addr *inaddr);
```
**Parameters**:
- `inaddr` Address to set.
**IPv6 Address Management**
### netlib_add_ipv6addr
```c
int netlib_add_ipv6addr(const char *ifname, const struct in6_addr *addr, uint8_t preflen);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to add.
- `preflen` Prefix length (in bits).
### netlib_del_ipv6addr
```c
int netlib_del_ipv6addr(const char *ifname, const struct in6_addr *addr, uint8_t preflen);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to delete.
- `preflen` Prefix length (in bits).
### netlib_get_ipv6addr
```c
int netlib_get_ipv6addr(const char *ifname, struct in6_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Used to store the IP address.
### netlib_set_ipv6addr
```c
int netlib_set_ipv6addr(const char *ifname, const struct in6_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to set.
### netlib_set_dripv6addr
```c
int netlib_set_dripv6addr(const char *ifname, const struct in6_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to set.
### netlib_set_ipv6netmask
```c
int netlib_set_ipv6netmask(const char *ifname, const struct in6_addr *addr);
```
**Parameters**:
- `ifname` Network interface name.
- `ipaddr` Address to set.
### netlib_ipv6adaptor
```c
int netlib_ipv6adaptor(const struct in6_addr *destipaddr, struct in6_addr *srcipaddr);
```
**Parameters**:
- `destipaddr` Target IP address.
- `srcipaddr` Used to store the adapter address.
### netlib_ipv6netmask2prefix
```c
uint8_t netlib_ipv6netmask2prefix(const uint16_t *mask);
```
**Parameters**:
- `mask` Subnet mask.
### netlib_prefix2ipv6netmask
```c
void netlib_prefix2ipv6netmask(uint8_t preflen, struct in6_addr *netmask);
```
**Parameters**:
- `preflen` Prefix length (in bits).
- `netmask` Used to store the subnet mask.
### netlib_read_ipv6route
```c
ssize_t netlib_read_ipv6route(FILE *stream, struct netlib_ipv6_route_s *route);
```
**Parameters**:
- `fd` Routing entry.
- `route` Used to store the next routing entry.
### netlib_ipv6router
```c
int netlib_ipv6router(const struct in6_addr *destipaddr, struct in6_addr *router);
```
**Parameters**:
- `destipaddr` Target IP address.
- `router` Used to store the IP address of the gateway router.
### netlib_obtain_ipv6addr
```c
int netlib_obtain_ipv6addr(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
### netlib_set_ipv6dnsaddr
```c
int netlib_set_ipv6dnsaddr(const struct in6_addr *inaddr);
```
**Parameters**:
- `inaddr` Address to set.
**Interface Management**
### netlib_setmacaddr
```c
int netlib_setmacaddr(const char *ifname, const uint8_t *macaddr);
```
**Parameters**:
- `ifname` Network interface name.
- `macaddr` MAC address.
### netlib_getmacaddr
```c
int netlib_getmacaddr(const char *ifname, uint8_t *macaddr);
```
**Parameters**:
- `ifname` Network interface name.
- `macaddr` Used to store the MAC address.
### netlib_getessid
```c
int netlib_getessid(const char *ifname, char *essid, size_t idlen);
```
**Parameters**:
- `ifname` Network interface name.
- `essid` Used to store the result.
- `idlen` ESSID buffer size.
### netlib_setessid
```c
int netlib_setessid(const char *ifname, const char *essid);
```
**Parameters**:
- `ifname` Network interface name.
- `essid` ESSID (network name).
### netlib_getifstatus
```c
int netlib_getifstatus(const char *ifname, uint8_t *flags);
```
**Parameters**:
- `ifname` Network interface name.
- `flags` Interface flags.
### netlib_ifup
```c
int netlib_ifup(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
### netlib_ifdown
```c
int netlib_ifdown(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
### netlib_set_mtu
```c
int netlib_set_mtu(const char *ifname, int mtu);
```
**Parameters**:
- `ifname` Network interface name.
- `mtu` Maximum Transmission Unit (MTU).
**Returns**:
:
### netlib_getifstatistics
```c
int netlib_getifstatistics(const char *ifname, struct netdev_statistics_s *stat);
```
**Parameters**:
- `ifname` Network interface name.
- `stat` Used to store device statistics.
### netlib_check_ifconflict
```c
int netlib_check_ifconflict(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
**Route Management**
### netlib_get_route
```c
ssize_t netlib_get_route(struct rtentry *rtelist, unsigned int nentries, sa_family_t family);
```
**Parameters**:
- `rtelist` Used to store the device list.
- `nentries` Array capacity (entry count).
- `family` Address family. See AF_* definitions in.
**ARP Management**
### netlib_del_arpmapping
```c
int netlib_del_arpmapping(const struct sockaddr_in *inaddr, const char *ifname);
```
**Parameters**:
- `inaddr` IPv4 address.
- `ifname` Network interface name.
### netlib_get_arpmapping
```c
int netlib_get_arpmapping(const struct sockaddr_in *inaddr, uint8_t *macaddr, const char *ifname);
```
**Parameters**:
- `inaddr` IPv4 address.
- `macaddr` Used to store the corresponding Ethernet MAC address.
- `ifname` Network interface name.
### netlib_set_arpmapping
```c
int netlib_set_arpmapping(const struct sockaddr_in *inaddr, const uint8_t *macaddr, const char *ifname);
```
**Parameters**:
- `inaddr` IPv4 address.
- `macaddr` MAC address.
- `ifname` Network interface name.
### netlib_get_arptable
```c
ssize_t netlib_get_arptable(struct arpreq *arptab, unsigned int nentries);
```
**Parameters**:
- `arptab` Used to store a copy of the ARP table.
- `nentries` Array capacity (entry count).
### netlib_ifarp
```c
int netlib_ifarp(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
### netlib_ifnoarp
```c
int netlib_ifnoarp(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
**DNS Management**
### netlib_clear_dnsaddr
```c
void netlib_clear_dnsaddr(void);
```
**VLAN Management**
### netlib_add_vlan
```c
int netlib_add_vlan(const char *ifname, int vlanid, int prio);
```
**Parameters**:
- `ifname` Network interface name.
- `vlanid` VLAN identifier.
- `prio` Default VLAN priority (PCP).
### netlib_del_vlan
```c
int netlib_del_vlan(const char *vlanif);
```
**iptables**
### netlib_ipt_commit
```c
int netlib_ipt_commit(const struct ipt_replace *repl);
```
**Parameters**:
- `repl` Configuration to commit.
### netlib_ipt_flush
```c
int netlib_ipt_flush(const char *table, enum nf_inet_hooks hook);
```
**Parameters**:
- `table` Table name.
- `hook` Hook point.
### netlib_ipt_policy
```c
int netlib_ipt_policy(const char *table, enum nf_inet_hooks hook, int verdict);
```
**Parameters**:
- `table` Policy.
- `hook` Hook point.
- `verdict` Verdict value.
### netlib_ipt_append
```c
int netlib_ipt_append(struct ipt_replace **repl, const struct ipt_entry *entry, enum nf_inet_hooks hook);
```
**Parameters**:
- `repl` Configuration to commit.
- `entry` Rule entry to append.
- `hook` Hook point.
### netlib_ipt_insert
```c
int netlib_ipt_insert(struct ipt_replace **repl, const struct ipt_entry *entry, enum nf_inet_hooks hook, int rulenum);
```
**Parameters**:
- `repl` Configuration to commit.
- `entry` Rule entry to insert.
- `hook` Hook point.
- `rulenum` Rule number.
### netlib_ipt_delete
```c
int netlib_ipt_delete(struct ipt_replace *repl, const struct ipt_entry *entry, enum nf_inet_hooks hook, int rulenum);
```
**Parameters**:
- `repl` Configuration to commit.
- `entry` Rule entry to delete.
- `hook` Hook point.
- `rulenum` Rule number.
### netlib_ipt_fillifname
```c
int netlib_ipt_fillifname(struct ipt_entry *entry, const char *inifname, const char *outifname);
```
**Parameters**:
- `entry` Rule entry to fill.
- `inifname` Input device name; `NULL` means unchanged.
- `outifname` Output device name; `NULL` means unchanged.
### netlib_ip6t_commit
```c
int netlib_ip6t_commit(const struct ip6t_replace *repl);
```
**Parameters**:
- `repl` Configuration to commit.
### netlib_ip6t_flush
```c
int netlib_ip6t_flush(const char *table, enum nf_inet_hooks hook);
```
**Parameters**:
- `table` Table name.
- `hook` Hook point.
### netlib_ip6t_policy
```c
int netlib_ip6t_policy(const char *table, enum nf_inet_hooks hook, int verdict);
```
**Parameters**:
- `table` Policy.
- `hook` Hook point.
- `verdict` Verdict value.
### netlib_ip6t_append
```c
int netlib_ip6t_append(struct ip6t_replace **repl, const struct ip6t_entry *entry, enum nf_inet_hooks hook);
```
**Parameters**:
- `repl` Configuration to commit.
- `entry` Rule entry to append.
- `hook` Hook point.
### netlib_ip6t_insert
```c
int netlib_ip6t_insert(struct ip6t_replace **repl, const struct ip6t_entry *entry, enum nf_inet_hooks hook, int rulenum);
```
**Parameters**:
- `repl` Configuration to commit.
- `entry` Rule entry to insert.
- `hook` Hook point.
- `rulenum` Rule number.
### netlib_ip6t_delete
```c
int netlib_ip6t_delete(struct ip6t_replace *repl, const struct ip6t_entry *entry, enum nf_inet_hooks hook, int rulenum);
```
**Parameters**:
- `repl` Configuration to commit.
- `entry` Rule entry to delete.
- `hook` Hook point.
- `rulenum` Rule number.
### netlib_ip6t_fillifname
```c
int netlib_ip6t_fillifname(struct ip6t_entry *entry, const char *inifname, const char *outifname);
```
**Parameters**:
- `entry` Rule entry to fill.
- `inifname` Input device name; `NULL` means unchanged.
- `outifname` Output device name; `NULL` means unchanged.
**Connectivity Checks**
### netlib_check_ipconnectivity
```c
int netlib_check_ipconnectivity(const char *ip, int timeout, int retry);
```
**Parameters**:
- `ip` IPv4 address to check.
- `timeout` Timeout.
- `retry` Retry count.
### netlib_check_ifconnectivity
```c
int netlib_check_ifconnectivity(const char *ifname, int timeout, int retry);
```
**Parameters**:
- `ifname` Network interface name.
- `timeout` Timeout.
- `retry` Retry count.
**URL Parsing**
### netlib_parsehttpurl
```c
int netlib_parsehttpurl(const char *url, uint16_t *port, char *hostname, int hostlen, char *filename, int namelen);
```
**Parameters**:
- `url` HTTP-related parameter.
- `port` Pointer to a `uint16_t` used to store the parsed port number.
- `hostname` Buffer used to store the result.
- `hostlen` Buffer size.
- `filename` Buffer used to store the result.
- `namelen` Buffer size.
### netlib_parseurl
```c
int netlib_parseurl(const char *str, struct url_s *url);
```
### netlib_check_httpconnectivity
```c
int netlib_check_httpconnectivity(const char *host, const char *getmsg, int port, int expect_code);
```
**Parameters**:
- `host` Remote host address.
- `getmsg` HTTP-related parameter.
- `port` Port number.
- `expect_code` HTTP-related parameter.
**Others**
### netlib_get_devices
```c
ssize_t netlib_get_devices(struct netlib_device_s *devlist, unsigned int nentries, sa_family_t family);
```
**Parameters**:
- `devlist` Used to store the device list.
- `nentries` Array capacity (entry count).
- `family` Address family. See AF_* definitions in.
### netlib_seteaddr
```c
int netlib_seteaddr(const char *ifname, const uint8_t *eaddr);
```
**Parameters**:
- `ifname` Network interface name.
- `eaddr` New address.
### netlib_getpanid
```c
int netlib_getpanid(const char *ifname, uint8_t *panid);
```
**Parameters**:
- `ifname` Network interface name.
- `panid` Used to store the current PAN ID.
### netlib_getproperties
```c
int netlib_getproperties(const char *ifname, struct pktradio_properties_s *properties);
```
**Parameters**:
- `ifname` Network interface name.
- `nodeadd` Used to store the node address.
### netlib_setnodeaddr
```c
int netlib_setnodeaddr(const char *ifname, const struct pktradio_addr_s *nodeaddr);
```
**Parameters**:
- `ifname` Network interface name.
- `nodeadd` New address.
### netlib_getnodnodeaddr
```c
int netlib_getnodnodeaddr(const char *ifname, struct pktradio_addr_s *nodeaddr);
```
**Parameters**:
- `ifname` Network interface name.
- `nodeadd` Used to store the node address.
### netlib_get_nbtable
```c
ssize_t netlib_get_nbtable(struct neighbor_entry_s *nbtab, unsigned int nentries);
```
**Parameters**:
- `nbtab` Used to store a copy of the neighbor table.
- `nentries` Array capacity (entry count).
### netlib_icmpv6_autoconfiguration
```c
int netlib_icmpv6_autoconfiguration(const char *ifname);
```
**Parameters**:
- `ifname` Network interface name.
### netlib_parse_conntrack
```c
int netlib_parse_conntrack(const struct nlmsghdr *nlh, size_t len, struct netlib_conntrack_s *ct);
```
**Parameters**:
- `nlh` Netlink message to parse.
- `ct` Connection tracking entry.
### netlib_get_conntrack
```c
int netlib_get_conntrack(sa_family_t family, netlib_conntrack_cb_t cb);
```
**Parameters**:
- `family` Address family, used to filter conntrack entries.
- `cb` Connection tracking entry.
### netlib_listenon
```c
int netlib_listenon(uint16_t portno);
```
**Parameters**:
- `portno` Port number.
### netlib_server
```c
void netlib_server(uint16_t portno, pthread_startroutine_t handler, int stacksize);
```
**Parameters**:
- `portno` Port number.
- `handler` Task entry function.
- `stacksize` Stack size.
### netlib_get_iobinfo
```c
int netlib_get_iobinfo(struct iob_stats_s *iob);
```
**Parameters**:
- `iob` IOB information structure.
### netlib_ipv4addrconv
```c
bool netlib_ipv4addrconv(const char *addrstr, uint8_t *addr);
```
Convert an IPv4 address string (e.g., `"192.168.1.1"`) to a 4-byte binary array.
**Parameters**:
- `addrstr` IPv4 address string.
- `addr` Output buffer (4 bytes).
**Returns**:
Returns `true` on successful conversion, or `false` if the format is invalid.
### netlib_ethaddrconv
```c
bool netlib_ethaddrconv(const char *hwstr, uint8_t *hw);
```
Convert an Ethernet MAC address string (e.g., `"aa:bb:cc:dd:ee:ff"`) to a 6-byte binary array.
**Parameters**:
- `hwstr` MAC address string.
- `hw` Output buffer (6 bytes).
**Returns**:
Returns `true` on successful conversion, or `false` if the format is invalid.
### netlib_saddrconv
```c
bool netlib_saddrconv(const char *hwstr, uint8_t *hw);
```
Convert an IEEE 802.15.4 short address (2 bytes) string to binary form.
**Parameters**:
- `hwstr` Address string.
- `hw` Output buffer (2 bytes).
**Returns**:
Returns `true` on successful conversion, or `false` if the format is invalid.
### netlib_eaddrconv
```c
bool netlib_eaddrconv(const char *hwstr, uint8_t *hw);
```
Convert an IEEE 802.15.4 extended address (8 bytes) string to binary form.
**Parameters**:
- `hwstr` Address string.
- `hw` Output buffer (8 bytes).
**Returns**:
Returns `true` on successful conversion, or `false` if the format is invalid.
### netlib_nodeaddrconv
```c
bool netlib_nodeaddrconv(const char *addrstr,
struct pktradio_addr_s *nodeaddr);
```
Convert a pktradio node address string to a `pktradio_addr_s` structure.
**Parameters**:
- `addrstr` Node address string.
- `nodeaddr` Output structure pointer.
**Returns**:
Returns `true` on successful conversion, or `false` if the format is invalid.

View File

@ -1,770 +0,0 @@
\[ English | [简体中文](../../../zh-cn/api/network/wapi.md) \]
# Wireless Network Interface (WAPI) API
The `wapi_*` series of interfaces is a wrapper around Linux Wireless Extensions (WEXT), providing wireless network configuration, scanning, association, power management, country code, and PMKSA cache capabilities.
Header: `#include <wireless/wapi.h>`
## openvela Implementation Notes
- **Underlying mechanism**: Communicates with Wi-Fi drivers via the ioctl protocol of Linux Wireless Extensions (WEXT)
- **Supported scenarios**: Station (client) mode, AP mode, and promiscuous mode (depending on driver support)
- **Configuration dependency**: Requires `CONFIG_WIRELESS_WAPI` and the corresponding Wi-Fi chip driver to be enabled
- **Typical usage**:
- `wapi_set_ifup`/`wapi_set_ifdown` to bring the interface up or down
- `wapi_set_essid` + `wapi_set_mode` to configure the connection target
- `wapi_scan_*` / `wapi_escan_*` to scan surrounding APs
- `wapi_load_config` / `wapi_save_config` to persist configuration
- **Extended capabilities**: Interact with driver-specific features via interfaces such as `wapi_extend_params` / `wapi_set_pmksa`
## Wireless Network Interface
Header: `#include <wireless/wapi.h>`
wapi provides wireless network configuration interfaces, including SSID scanning, connection, and frequency setting.
**Connection Management**
### wapi_get_ifup
```c
int wapi_get_ifup(int sock, const char *ifname, int *is_up);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `is_up` Interface status; 0 means enabled, 1 means disabled.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_ifup
```c
int wapi_set_ifup(int sock, const char *ifname);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_ifdown
```c
int wapi_set_ifdown(int sock, const char *ifname);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name to be brought down.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_ip
```c
int wapi_get_ip(int sock, const char *ifname, struct in_addr *addr);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `addr` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_ip
```c
int wapi_set_ip(int sock, const char *ifname, const struct in_addr *addr);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name whose IP address is set.
- `addr` Pointer to the structure containing the new IP address.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_netmask
```c
int wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `addr` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_netmask
```c
int wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `addr` Pointer to the structure containing the new subnet mask.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_add_route_gw
```c
int wapi_add_route_gw(int sock, enum wapi_route_target_e targettype, const struct in_addr *target, const struct in_addr *netmask, const struct in_addr *gw);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `targettype` Target type.
- `target` Pointer to the target IP address.
- `netmask` Pointer to the subnet mask corresponding to the target address.
- `gw` Pointer to the corresponding gateway (router) IP address, used for routing.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_del_route_gw
```c
int wapi_del_route_gw(int sock, enum wapi_route_target_e targettype, const struct in_addr *target, const struct in_addr *netmask, const struct in_addr *gw);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `targettype` Target type.
- `target` Pointer to the target IP address of the route.
- `netmask` Pointer to the subnet mask corresponding to the target address.
- `gw` Pointer to the corresponding gateway (router) IP address, used for routing.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_freq
```c
int wapi_get_freq(int sock, const char *ifname, double *freq, enum wapi_freq_flag_e *flag);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `freq` Output parameter.
- `flag` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_freq
```c
int wapi_set_freq(int sock, const char *ifname, double freq, enum wapi_freq_flag_e flag);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `freq` Frequency value.
- `flag` Frequency value.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_freq2chan
```c
int wapi_freq2chan(int sock, const char *ifname, double freq, int *chan);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `freq` Frequency, in Hz, to be converted to a channel number.
- `chan` Output parameter.
### wapi_chan2freq
```c
int wapi_chan2freq(int sock, const char *ifname, int chan, double *freq);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Channel.
- `chan` Channel number to be converted to a frequency.
- `freq` Output parameter.
### wapi_get_essid
```c
int wapi_get_essid(int sock, const char *ifname, char *essid, enum wapi_essid_flag_e *flag);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `essid` Used to store the result.
- `flag` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_essid
```c
int wapi_set_essid(int sock, const char *ifname, const char *essid, enum wapi_essid_flag_e flag);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `essid` Pointer to a `\0`-terminated ESSID string.
- `flag` Control flag.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_mode
```c
int wapi_get_mode(int sock, const char *ifname, enum wapi_mode_e *mode);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `mode` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_mode
```c
int wapi_set_mode(int sock, const char *ifname, enum wapi_mode_e mode);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `mode` Output parameter.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_make_broad_ether
```c
int wapi_make_broad_ether(struct ether_addr *sa);
```
**Parameters**:
- `sa` Output parameter.
**Returns**:
Returns the result of the underlying `wapi_make_ether()` call.
### wapi_make_null_ether
```c
int wapi_make_null_ether(struct ether_addr *sa);
```
**Parameters**:
- `sa` Output parameter.
**Returns**:
Returns the result of the underlying `wapi_make_ether()` call.
### wapi_get_ap
```c
int wapi_get_ap(int sock, const char *ifname, struct ether_addr *ap);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `ap` Address to set.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_ap
```c
int wapi_set_ap(int sock, const char *ifname, const struct ether_addr *ap);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `ap` MAC address of the access point.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_bitrate
```c
int wapi_get_bitrate(int sock, const char *ifname, int *bitrate, enum wapi_bitrate_flag_e *flag);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `bitrate` Output parameter for the retrieved bitrate.
- `flag` Output parameter for the bitrate flag bits.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_bitrate
```c
int wapi_set_bitrate(int sock, const char *ifname, int bitrate, enum wapi_bitrate_flag_e flag);
```
**Parameters**:
- `sock` Socket descriptor (used for ioctl operations).
- `ifname` Network interface name.
- `bitrate` Bitrate.
- `flag` Bitrate flag.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_dbm2mwatt
```c
int wapi_dbm2mwatt(int dbm);
```
**Parameters**:
- `dbm` dBm value to convert.
**Returns**:
The converted milliwatt value.
### wapi_mwatt2dbm
```c
int wapi_mwatt2dbm(int mwatt);
```
**Parameters**:
- `mwatt` Milliwatt value.
**Returns**:
The converted dBm value.
### wapi_get_txpower
```c
int wapi_get_txpower(int sock, const char *ifname, int *power, enum wapi_txpower_flag_e *flag);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `power` Output parameter for the transmit power value.
- `flag` Output parameter for the unit of the transmit power.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_txpower
```c
int wapi_set_txpower(int sock, const char *ifname, int power, enum wapi_txpower_flag_e flag);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `power` Transmit power.
- `flag` Transmit power.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_make_socket
```c
int wapi_make_socket(void);
```
### wapi_scan_init
```c
int wapi_scan_init(int sock, const char *ifname, const char *essid);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `essid` ESSID to scan.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_scan_channel_init
```c
int wapi_scan_channel_init(int sock, const char *ifname, const char *essid, uint8_t *channels, int num_channels);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `essid` ESSID to scan.
- `channels` Pointer to an array of channel numbers to scan.
- `num_channels` Channel count.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_escan_init
```c
int wapi_escan_init(int sock, const char *ifname, uint8_t scan_type, const char *essid);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `scan_type` Scan type.
- `essid` ESSID to scan.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_escan_channel_init
```c
int wapi_escan_channel_init(int sock, const char *ifname, uint8_t scan_type, const char *essid, uint8_t *channels, int num_channels);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `scan_type` Scan type.
- `essid` ESSID to scan.
- `channels` Pointer to an array of channel numbers to scan.
- `num_channels` Channel count.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_scan_stat
```c
int wapi_scan_stat(int sock, const char *ifname);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
### wapi_scan_coll
```c
int wapi_scan_coll(int sock, const char *ifname, struct wapi_list_s *aps);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `aps` List of collected scan results.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_scan_coll_free
```c
void wapi_scan_coll_free(struct wapi_list_s *aps);
```
**Parameters**:
- `aps` Scan result list to free.
### wapi_set_country
```c
int wapi_set_country(int sock, const char *ifname, const char *country);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `country` Pointer to a two-character string indicating the country code to set.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_country
```c
int wapi_get_country(int sock, const char *ifname, char *country);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `country` Pointer to the caller-provided buffer to receive the country code.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_sensitivity
```c
int wapi_get_sensitivity(int sock, const char *ifname, int *sense);
```
**Parameters**:
- `sock` Socket descriptor.
- `ifname` Network interface name.
- `sense` Pointer to the caller-provided integer variable to receive the sensitivity value.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_load_config
```c
void *wapi_load_config(const char *ifname, const char *confname, struct wpa_wconfig_s *conf);
```
**Parameters**:
- `ifname` Network interface name.
- `confname` Path.
- `conf` Pointer to the caller-provided structure to be filled with configuration data.
### wapi_unload_config
```c
void wapi_unload_config(void *load);
```
**Parameters**:
- `load` Configuration resource handle.
### wapi_save_config
```c
int wapi_save_config(const char *ifname, const char *confname, const struct wpa_wconfig_s *conf);
```
**Parameters**:
- `ifname` Network interface name.
- `confname` Path.
- `conf` Pointer to the structure containing the configuration information.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_pta_prio
```c
int wapi_set_pta_prio(int sock, const char *ifname, enum wapi_pta_prio_e pta_prio);
```
**Parameters**:
- `sock` File descriptor.
- `ifname` Network interface name.
- `pta_prio` PTA priority.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_pta_prio
```c
int wapi_get_pta_prio(int sock, const char *ifname, enum wapi_pta_prio_e *pta_prio);
```
**Parameters**:
- `sock` File descriptor.
- `ifname` Network interface name.
- `pta_prio` Pointer to the variable that receives the current PTA priority.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_pmksa
```c
int wapi_set_pmksa(int sock, const char *ifname, const uint8_t *pmk, int len);
```
**Parameters**:
- `sock` File descriptor.
- `ifname` Network interface name.
- `pmk` Pointer to the buffer containing the PMKSA data.
- `len` Length.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_pmksa
```c
int wapi_get_pmksa(int sock, const char *ifname, uint8_t *pmk, int len);
```
**Parameters**:
- `sock` File descriptor.
- `ifname` Network interface name.
- `pmk` Pointer to the buffer that receives the retrieved PMKSA data.
- `len` Buffer size.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_extend_params
```c
int wapi_extend_params(int sock, int cmd, struct iwreq *wrq);
```
**Parameters**:
- `sock` File descriptor.
- `cmd` Private ioctl command code.
- `wrq` Pointer to an `iwreq` structure that the caller must populate in advance.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_set_power_save
```c
int wapi_set_power_save(int sock, const char *ifname, bool on);
```
**Parameters**:
- `sock` File descriptor.
- `ifname` Network interface name.
- `on` Control flag.
**Returns**:
Returns 0 on success, or a negative error code on failure.
### wapi_get_power_save
```c
int wapi_get_power_save(int sock, const char *ifname, bool *on);
```
**Parameters**:
- `sock` File descriptor.
- `ifname` Network interface name.
- `on` Pointer to a boolean variable that receives the current state.
**Returns**:
Returns 0 on success, or a negative error code on failure.

View File

@ -1,11 +1,11 @@
# Developing an openvela UI Application
\[ English | [简体中文](../../../zh-cn/app_dev/system_apps/Dev_UI_App.md) \]
[ English | [简体中文](../../../zh-cn/app_dev/system_apps/Dev_UI_App.md) ]
## I. Prerequisites
1. Download the source code. Please refer to [Quick Start](./../../quickstart/openvela_ubuntu_quick_start.md).
2. Before starting this tutorial, please obtain the example code from [music_player](../../../../../../packages_demos/tree/dev/music_player).
2. Before starting this tutorial, please obtain the example code from [music_player](../../../../../../packages_demos/tree/trunk/music_player).
## II. Preliminary Concepts

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -125,7 +125,7 @@ The following are the interrupt-related functions that vendors need to implement
### 2. Required Interrupt-Related Macros
Alongside the above function implementations, vendors need to define a series of interrupt-related macros, which describe the configuration of the NVIC (Nested Vectored Interrupt Controller). These macros should be defined in the `chips/chip_name/include/irq.h` file. Refer to the [RTL8720C example](../../../../../nuttx/blob/dev/arch/arm/src/rtl8720c/include/irq.h) for guidance.
Alongside the above function implementations, vendors need to define a series of interrupt-related macros, which describe the configuration of the NVIC (Nested Vectored Interrupt Controller). These macros should be defined in the `chips/chip_name/include/irq.h` file. Refer to the [RTL8720C example](../../../../../nuttx/blob/trunk/arch/arm/src/rtl8720c/include/irq.h) for guidance.
The required macros and their descriptions are as follows:

View File

@ -96,7 +96,7 @@ CONFIG_FRAME_POINTER=y
CONFIG_SCHED_BACKTRACE=y
```
For more information, refer to: [RISC-V Backtrace Implementation](../../../../../../nuttx/blob/dev/arch/risc-v/src/common/riscv_backtrace.c).
For more information, refer to: [RISC-V Backtrace Implementation](../../../../../../nuttx/blob/trunk/arch/risc-v/src/common/riscv_backtrace.c).
### 4. Xtensa

View File

@ -8,6 +8,6 @@
| STMicroelectronics | STM32F411CEU6 | [STM32F411CE](https://www.st.com/en/microcontrollers-microprocessors/stm32f411ce.html) | [Blink an LED with openvela on STM32F411](../quickstart/development_board/STM32F411.md) | IoT, Industrial Automation | [ST MCU China Support](mailto:mcu.china@st.com) |
| Espressif | [ESP32-S3-EYE](https://www.espressif.com/en/dev-board/esp32-s3-eye) | [ESP32-S3](https://www.espressif.com/en/products/socs/esp32-s3) | [Port openvela to the ESP32-S3-EYE Dev Board](../quickstart/development_board/ESP32-S3-EYE.md) | AIoT, HMI, Smart Home | [Espressif Developer Community](https://www.espressif.com/en/contact-us/technical-inquiries) |
| Espressif | [ESP32-S3-BOX](https://www.espressif.com/en/news/ESP32-S3-BOX_video) | [ESP32-S3](https://www.espressif.com/en/products/socs/esp32-s3) | [See: Port openvela to the ESP32-S3-EYE Dev Board](../quickstart/development_board/ESP32-S3-EYE.md) | AIoT, HMI, Smart Home | [Espressif Developer Community](https://www.espressif.com/en/contact-us/technical-inquiries) |
| Bestechnic | [BES2600WM MAIN BOARD V1.1](https://www.fortune-co.com/index.php?s=/Cn/Public/singlePage/catid/176.html) | BES2600WM-AX4F | [Readme](../../../../../vendor_bes/blob/dev/boards/best2003_ep/aos_evb/Readme) | Smart Wearables, AI Toys | [Contact Distributor](https://www.fortune-co.com/Tech/projectDetail/id/64.html) |
| Bestechnic | [BES2600WM MAIN BOARD V1.1](https://www.fortune-co.com/index.php?s=/Cn/Public/singlePage/catid/176.html) | BES2600WM-AX4F | [Readme](../../../../../vendor_bes/blob/trunk/boards/best2003_ep/aos_evb/Readme) | Smart Wearables, AI Toys | [Contact Distributor](https://www.fortune-co.com/Tech/projectDetail/id/64.html) |
| Flagchip | [FC7300F8M-EVB](https://www.flagchip.com.cn/Pro/3/3.html) | [FC7300F8MDT](https://www.flagchip.com.cn/Pro/3/3.html) | [openvela Running Guide for FC7300F8M-EVB](../quickstart/development_board/fc7300f8m_evb_guide.md) | Domain/Zonal Controllers, ADAS, BMS, Motor Control, etc. | [Contact Distributor](https://www.flagchip.com.cn/Pro/3/3.html) | [Contact Distributor](https://www.flagchip.com.cn/Pro/3/3.html) |
| Infineon | [TC4D9-EVB](https://itools.infineon.com/aurix_tc4xx_code_examples/documents/Board_Users_Manual_TriBoard-TC4X9-COM-V2_0_0.pdf) | [AURIX ™ TC4x](https://www.infineon.cn/products/microcontroller/32-bit-tricore/aurix-tc4x/tc4dx#products) | [openvela Running Guide for TC4D9-EVB](../quickstart/development_board/tc4d9_evb_guide.md) | Vehicle Motion Controllers, Zonal Controllers, Automotive Gateways, etc. | [Contact Distributor](https://www.infineon.cn/contact-us/where-to-buy) | [Contact Distributor](https://www.infineon.cn/contact-us/where-to-buy) |

View File

@ -19,20 +19,20 @@ The implementation of these member functions depends on the actual operation of
#### Note
- To quickly validate custom callbacks and driver registration in a QEMU environment, this example implements the `struct bt_driver_s` member functions directly within the [drivers_initialize](../../../../../../../nuttx/blob/dev/drivers/drivers_initialize.c) function and completes driver registration.
- In a real integration or production scenario, it is recommended to create a separate source file under the [vendor](../../../../../../../vendor_template/blob/dev/boards/chip_name/board_name/src) directory for maintainability and version control.
- To quickly validate custom callbacks and driver registration in a QEMU environment, this example implements the `struct bt_driver_s` member functions directly within the [drivers_initialize](../../../../../../../nuttx/blob/trunk/drivers/drivers_initialize.c) function and completes driver registration.
- In a real integration or production scenario, it is recommended to create a separate source file under the [vendor](../../../../../../../vendor_template/blob/trunk/boards/chip_name/board_name/src) directory for maintainability and version control.
#### Steps
1. In [drivers_initialize.c](../../../../../../../nuttx/blob/dev/drivers/drivers_initialize.c), add the [bt_driver.h](../../../../../../../nuttx/blob/dev/include/nuttx/wireless/bluetooth/bt_driver.h) header include:
1. In [drivers_initialize.c](../../../../../../../nuttx/blob/trunk/drivers/drivers_initialize.c), add the [bt_driver.h](../../../../../../../nuttx/blob/trunk/include/nuttx/wireless/bluetooth/bt_driver.h) header include:
```C
#include <nuttx/wireless/bluetooth/bt_driver.h> /* Add bt_driver.h header include */
```
2. In [drivers_initialize.c](../../../../../../../nuttx/blob/dev/drivers/drivers_initialize.c), implement the member functions.
2. In [drivers_initialize.c](../../../../../../../nuttx/blob/trunk/drivers/drivers_initialize.c), implement the member functions.
In openvela, the `receive` member function of `struct bt_driver_s` already has a default implementation in [uart_bth4.c](../../../../../../../nuttx/blob/dev/drivers/serial/uart_bth4.c). Therefore, developers or vendors do not need to redefine or implement this method.
In openvela, the `receive` member function of `struct bt_driver_s` already has a default implementation in [uart_bth4.c](../../../../../../../nuttx/blob/trunk/drivers/serial/uart_bth4.c). Therefore, developers or vendors do not need to redefine or implement this method.
```C
/* The following are sample implementations for demonstration only.
@ -68,7 +68,7 @@ The implementation of these member functions depends on the actual operation of
/* 4. The receive member function is assigned by openvela at registration time */
```
3. In [drivers_initialize.c](../../../../../../../nuttx/blob/dev/drivers/drivers_initialize.c), define the `struct bt_driver_s` structure.
3. In [drivers_initialize.c](../../../../../../../nuttx/blob/trunk/drivers/drivers_initialize.c), define the `struct bt_driver_s` structure.
The following code shows a complete example of initializing a `struct bt_driver_s` instance, where the function pointers are assigned to the sample functions defined above:
@ -94,7 +94,7 @@ After implementing the above structure, register the driver instance using one o
- `bt_driver_register_with_id(FAR struct bt_driver_s *driver, int id)`: Registers with the specified id
The type definition `int bt_driver_register(FAR struct bt_driver_s *drv)` can be found in the header [bt_driver.h](../../../../../../../nuttx/blob/dev/include/nuttx/wireless/bluetooth/bt_driver.h). Vendors or developers do not need to define the `receive()` member function; the BTH4 driver will initialize it.
The type definition `int bt_driver_register(FAR struct bt_driver_s *drv)` can be found in the header [bt_driver.h](../../../../../../../nuttx/blob/trunk/include/nuttx/wireless/bluetooth/bt_driver.h). Vendors or developers do not need to define the `receive()` member function; the BTH4 driver will initialize it.
The call flow is shown below:
@ -102,7 +102,7 @@ The call flow is shown below:
### Example
After completing the driver implementation example above, call the driver registration API at the end of the `drivers_initialize()` function in [drivers_initialize.c](../../../../../../../nuttx/blob/dev/drivers/drivers_initialize.c) to complete the driver registration:
After completing the driver implementation example above, call the driver registration API at the end of the `drivers_initialize()` function in [drivers_initialize.c](../../../../../../../nuttx/blob/trunk/drivers/drivers_initialize.c) to complete the driver registration:
```C
void drivers_initialize(void)

View File

@ -85,7 +85,7 @@ In openvela, the application layer accesses drivers through system calls, with t
**System call -> VFS (Virtual File System) -> Driver**.
To understand how drivers are registered with the file system, it is necessary to first understand the relevant data structures. The definitions of these data structures are located in the [include/nuttx/fs/fs.h](../../../../../../nuttx/blob/dev/include/nuttx/fs/fs.h) file.
To understand how drivers are registered with the file system, it is necessary to first understand the relevant data structures. The definitions of these data structures are located in the [include/nuttx/fs/fs.h](../../../../../../nuttx/blob/trunk/include/nuttx/fs/fs.h) file.
#### Driver Registration and `inode`

View File

@ -18,7 +18,7 @@ Openvela provides a generic **oneshot** driver, which is a one-time (non-periodi
- **Upper Half**: Application-facing, provided by openvela, and does not require modification by chip vendors.
- **Lower Half**: Platform-specific hardware control driver, which chip vendors need to adapt and provide.
The **oneshot** driver-related interface information is in the [oneshot.h](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/oneshot.h) file, and is also divided into **Upper Half** and **Lower Half** interface layers.
The **oneshot** driver-related interface information is in the [oneshot.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/oneshot.h) file, and is also divided into **Upper Half** and **Lower Half** interface layers.
### 2. Arch_alarm Timer Introduction
@ -47,7 +47,7 @@ The **`up_timer_initialize`** function in the Upper Half of openvela must be imp
## III. Arch_alarm API
`arch_alarm` provides a series of interfaces to meet the timer requirements of the sched module. Interface information can be found in the [arch.h](../../../../../../../../nuttx/blob/dev/include/nuttx/arch.h) header file.
`arch_alarm` provides a series of interfaces to meet the timer requirements of the sched module. Interface information can be found in the [arch.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/arch.h) header file.
### 1. Interface Classification
@ -193,7 +193,7 @@ In the openvela board adaptation, the initialization of the Oneshot timer requir
##### Instance Creation: Call `oneshot_initialize`
During the board initialization phase, it is necessary to invoke the **vendor-customized initialization function** to complete the allocation and initialization of the [struct oneshot_lowerhalf_s](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/oneshot.h#L226) structure. This function is provided by the openvela framework, with the prototype as follows:
During the board initialization phase, it is necessary to invoke the **vendor-customized initialization function** to complete the allocation and initialization of the [struct oneshot_lowerhalf_s](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/oneshot.h#L226) structure. This function is provided by the openvela framework, with the prototype as follows:
```C
/****************************************************************************
@ -224,7 +224,7 @@ Operation Instructions:
##### Device Registration: Call `oneshot_register`
Bind the instance returned by `oneshot_initialize` to the system device model, register the character device node (e.g., `/dev/oneshot`), and associate it with the file operation interface `struct file_operations g_oneshot_ops`. The prototype of the function [oneshot_register](../../../../../../../../nuttx/blob/dev/drivers/timers/oneshot.c#L291) is as follows:
Bind the instance returned by `oneshot_initialize` to the system device model, register the character device node (e.g., `/dev/oneshot`), and associate it with the file operation interface `struct file_operations g_oneshot_ops`. The prototype of the function [oneshot_register](../../../../../../../../nuttx/blob/trunk/drivers/timers/oneshot.c#L291) is as follows:
```C
/****************************************************************************
@ -272,7 +272,7 @@ Key Role:
#### 2.2 Reference Implementation and Debugging
- Structure Definition: For details on the members of `struct oneshot_lowerhalf_s`, refer to [oneshot.h](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/oneshot.h#L226). Fill in function pointers such as interrupt triggering and timer startup according to hardware characteristics.
- Structure Definition: For details on the members of `struct oneshot_lowerhalf_s`, refer to [oneshot.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/oneshot.h#L226). Fill in function pointers such as interrupt triggering and timer startup according to hardware characteristics.
- Example Code: For specific driver adaptation examples, refer to the [Driver Adaptation Example - Initialization Section](#1-initialization-process), and adjust the hardware register operation logic according to the target platform (e.g., ARM Cortex-M/RISC-V).
- Debugging Suggestions: If initialization fails, check whether `CONFIG_ONESHOT`/`CONFIG_ALARM_ARCH` are correctly enabled, and use serial port logs to print the return value of `oneshot_initialize`.
@ -296,7 +296,7 @@ Design Principles:
#### 3.2 Core Interface Description
Upper-Half interfaces are defined in [arch.h](../../../../../../../../nuttx/blob/dev/include/nuttx/arch.h#L1460), primarily for use by the scheduler (Sched).
Upper-Half interfaces are defined in [arch.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/arch.h#L1460), primarily for use by the scheduler (Sched).
### 4. Lower-Half Interfaces
@ -323,7 +323,7 @@ This interface supports two time units (`struct timespec` and `tick`). Developer
- Vendor Selection
- Choose to implement the `timespec` or `tick` interface group based on hardware capabilities.
- Unimplemented interface groups can be automatically mapped via openvela's built-in [conversion functions](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/oneshot.h).
- Unimplemented interface groups can be automatically mapped via openvela's built-in [conversion functions](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/oneshot.h).
- Performance Optimization
@ -331,7 +331,7 @@ This interface supports two time units (`struct timespec` and `tick`). Developer
#### 4.2 Core Interface Description
`struct oneshot_operations_s` is defined in [oneshot.h](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/oneshot.h), with the following member functions.
`struct oneshot_operations_s` is defined in [oneshot.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/oneshot.h), with the following member functions.
##### Timer Control Interfaces
@ -432,7 +432,7 @@ board_late_initialize (or board_app_initialize)
#### 1.2 Key Code Implementation
- Hardware (Arch Layer) Timer Initialization, refer to code [arch/risc-v/src/bl602/bl602_timerisr.c](../../../../../../../../nuttx/blob/dev/arch/risc-v/src/bl602/bl602_timerisr.c#L57).
- Hardware (Arch Layer) Timer Initialization, refer to code [arch/risc-v/src/bl602/bl602_timerisr.c](../../../../../../../../nuttx/blob/trunk/arch/risc-v/src/bl602/bl602_timerisr.c#L57).
```C
/****************************************************************************
@ -456,7 +456,7 @@ board_late_initialize (or board_app_initialize)
}
```
- Oneshot Driver Instantiation, refer to code [arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c](../../../../../../../../nuttx/blob/dev/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c#L361).
- Oneshot Driver Instantiation, refer to code [arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c](../../../../../../../../nuttx/blob/trunk/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c#L361).
```C
struct oneshot_lowerhalf_s *oneshot_initialize(int chan,
@ -520,7 +520,7 @@ board_late_initialize (or board_app_initialize)
### 2. Lower-Half Interface Implementation
The operation interface binding is as follows, and the detailed code can be referred to in [arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c](../../../../../../../../nuttx/blob/dev/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c#L96).
The operation interface binding is as follows, and the detailed code can be referred to in [arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c](../../../../../../../../nuttx/blob/trunk/arch/risc-v/src/bl602/bl602_oneshot_lowerhalf.c#L96).
```C
/* "Lower half" driver methods */
@ -545,7 +545,7 @@ Below is a brief introduction to the timer API. For detailed information, refer
man timer_create
```
Detailed code can be found in [include/time.h](../../../../../../../../nuttx/blob/dev/include/time.h#L233).
Detailed code can be found in [include/time.h](../../../../../../../../nuttx/blob/trunk/include/time.h#L233).
```C
/*
@ -600,7 +600,7 @@ int timer_getoverrun(timer_t timerid);
### 2. IOCTL API
Applications can directly operate the Oneshot timer through the `ioctl` function. Before using this feature, the `/dev/oneshot` device node must be registered during the system startup (bringup) process. Refer to the header file [include/nuttx/timers/oneshot.h](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/oneshot.h#L41) for the currently supported `ioctl` commands. Command descriptions are as follows:
Applications can directly operate the Oneshot timer through the `ioctl` function. Before using this feature, the `/dev/oneshot` device node must be registered during the system startup (bringup) process. Refer to the header file [include/nuttx/timers/oneshot.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/oneshot.h#L41) for the currently supported `ioctl` commands. Command descriptions are as follows:
- `OSIOC_START`

View File

@ -164,15 +164,15 @@ grep -rE "CONFIG_TIMER|CONFIG_TIMER_ARCH|CONFIG_ARCH_HAVE_TICKLESS|CONFIG_ARCH_H
During **board** initialization, the `***_timer_initialize` function implemented by the specific **Vendor** needs to be called to complete initialization. This function will perform the following operations:
1. Allocate and initialize an instance of [struct timer_lowerhalf_s](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/timer.h).
2. Register the `timer_lowerhalf_s` instance as a Timer driver using the [timer_register](../../../../../../../../nuttx/blob/dev/drivers/timers/timer.c) function.
1. Allocate and initialize an instance of [struct timer_lowerhalf_s](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/timer.h).
2. Register the `timer_lowerhalf_s` instance as a Timer driver using the [timer_register](../../../../../../../../nuttx/blob/trunk/drivers/timers/timer.c) function.
- The registration process generates the `/dev/timer` device node.
- Simultaneously binds the `struct file_operations` and `g_timerops` instances to the `timer_lowerhalf_s` instance.
In the platform code, the `up_timer_initialize` function needs to be implemented to call the `up_timer_set_lowerhalf` function, binding the instance returned by `***_timer_initialize` to the system as the system timer.
Related interface definitions are in: [/include/nuttx/timers/timer.h](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/timer.h).
Related interface definitions are in: [/include/nuttx/timers/timer.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/timer.h).
#### `timer_register` Function Description
@ -244,7 +244,7 @@ The `lower-half` driver provides standardized `struct timer_ops_s` interfaces fo
#### Interface Definitions
The following is the detailed definition of [struct timer_ops_s](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/timer.h):
The following is the detailed definition of [struct timer_ops_s](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/timer.h):
```c
struct timer_ops_s
@ -486,7 +486,7 @@ The lower-half is the driver interface part that implements hardware functions,
In the ARMv7-M Arch Timer adaptation, the lower-half methods appear as follows:
File path: [arch/arm/src/armv7-m/arm_systick.c](../../../../../../../../nuttx/blob/dev/arch/arm/src/armv7-m/arm_systick.c)
File path: [arch/arm/src/armv7-m/arm_systick.c](../../../../../../../../nuttx/blob/trunk/arch/arm/src/armv7-m/arm_systick.c)
```c
/* "Lower half" driver methods */
@ -509,7 +509,7 @@ This chapter briefly introduces POSIX API interfaces related to timers and clock
The following is a brief overview of timing-related POSIX APIs. For specific usage of these interfaces, please refer to the relevant `man` pages.
Header file location: [include/time.h](../../../../../../../../nuttx/blob/dev/include/time.h)
Header file location: [include/time.h](../../../../../../../../nuttx/blob/trunk/include/time.h)
1. `timer_create`
@ -584,7 +584,7 @@ Application-level programs can directly operate the timer through the `ioctl` fu
#### Supported IOCTL Commands
The following are currently supported IOCTL commands, with related interface definitions in [include/nuttx/timers/timer.h](../../../../../../../../nuttx/blob/dev/include/nuttx/timers/timer.h):
The following are currently supported IOCTL commands, with related interface definitions in [include/nuttx/timers/timer.h](../../../../../../../../nuttx/blob/trunk/include/nuttx/timers/timer.h):
- `TCIOC_START`: Start the timer.
- `TCIOC_STOP`: Stop the timer.

View File

@ -60,7 +60,7 @@ openvela's Framebuffer user interface resembles Linux systems, offering standard
### 2. Lower-level Driver Interface
openvela's Framebuffer driver interface for managing LCD devices is designed with simplicity. Developers can refer to [video/fb.h](../../../../../../nuttx/blob/dev/include/nuttx/video/fb.h) and [/drivers/video/fb.c](../../../../../../nuttx/blob/dev/drivers/video/fb.c). Below is the `fb_register()` source code showing key parts of the Framebuffer device driver implementation:
openvela's Framebuffer driver interface for managing LCD devices is designed with simplicity. Developers can refer to [video/fb.h](../../../../../../nuttx/blob/trunk/include/nuttx/video/fb.h) and [/drivers/video/fb.c](../../../../../../nuttx/blob/trunk/drivers/video/fb.c). Below is the `fb_register()` source code showing key parts of the Framebuffer device driver implementation:
```C
int fb_register(int display, int plane)
@ -340,6 +340,5 @@ To prevent screen tearing and improve rendering performance, it is recommended t
Here are the links to the code repository related to Framebuffer driver:
- [fb.c](../../../../../../nuttx/blob/dev/drivers/video/fb.c)Framebuffer Implementation files of the driver.
- [fb.h](../../../../../../nuttx/blob/dev/include/nuttx/video/fb.h)Framebuffer Interface definitions of the driver.
- [fb.c](../../../../../../nuttx/blob/trunk/drivers/video/fb.c)Framebuffer Implementation files of the driver.
- [fb.h](../../../../../../nuttx/blob/trunk/include/nuttx/video/fb.h)Framebuffer Interface definitions of the driver.

View File

@ -352,6 +352,6 @@ In LCD Framebuffer mode, you need to enable the following build options:
## V. Related Repositories
- [nuttx/include/nuttx/lcd/lcd.h](../../../../../../nuttx/blob/dev/include/nuttx/lcd/lcd.h)
- [nuttx/include/nuttx/lcd/lcd.h](../../../../../../nuttx/blob/trunk/include/nuttx/lcd/lcd.h)
- [nuttx/drivers/lcd/lcd_framebuffer.c](../../../../../../nuttx/blob/dev/drivers/lcd/lcd_framebuffer.c)
- [nuttx/drivers/lcd/lcd_framebuffer.c](../../../../../../nuttx/blob/trunk/drivers/lcd/lcd_framebuffer.c)

View File

@ -127,7 +127,7 @@ In most application scenarios, development is based on [libuv](https://libuv.org
The core of libuv is based on [poll](https://man7.org/linux/man-pages/man2/poll.2.html). Compared to traditional semaphores, the key advantage of `poll` is its ability to monitor multiple events simultaneously. `poll` exits its blocking state as soon as any one of the monitored events occurs. The principle of libuv is illustrated in the figure below:
The openvela framebuffer driver framework provides the necessary [interface](../../../../../../nuttx/blob/dev/drivers/video/fb.c) for `poll` to monitor whether the framebuffer is in a writable state:
The openvela framebuffer driver framework provides the necessary [interface](../../../../../../nuttx/blob/trunk/drivers/video/fb.c) for `poll` to monitor whether the framebuffer is in a writable state:
```C
/****************************************************************************
@ -520,7 +520,7 @@ static void lcdc_te_irq(int irq, void *context, void *arg)
### 2. (Not Recommended) Blocking Mode
Using semaphores for synchronization is equivalent to locking the framebuffer. The renderer must acquire the lock before each rendering operation; otherwise, it will be blocked. For the code, see this [link](../../../../../../nuttx/blob/dev/arch/arm/src/stm32/stm32_ltdc.c).
Using semaphores for synchronization is equivalent to locking the framebuffer. The renderer must acquire the lock before each rendering operation; otherwise, it will be blocked. For the code, see this [link](../../../../../../nuttx/blob/trunk/arch/arm/src/stm32/stm32_ltdc.c).
## V Related Repositories

View File

@ -292,7 +292,7 @@ When a thread attempts to acquire an unavailable semaphore:
#### References
- For a detailed explanation of semaphores, see [Semaphore Mechanism](./resource_sync/semaphore_mechanism.md).
- For the relevant implementation code, see [openvela Semaphore](../../../../../../../open-vela/nuttx/tree/dev/sched/semaphore).
- For the relevant implementation code, see [openvela Semaphore](../../../../../../../open-vela/nuttx/tree/trunk/sched/semaphore).
### 2. Mutexes
@ -311,7 +311,7 @@ A mutex (mutual exclusion) is a sleeping lock that enforces mutual exclusion. In
#### References
- The implementation code can be found at [openvela Mutex](../../../../../../../open-vela/nuttx/tree/dev/libs/libc/misc/lib_mutex.c).
- The implementation code can be found at [openvela Mutex](../../../../../../../open-vela/nuttx/tree/trunk/libs/libc/misc/lib_mutex.c).
### 3. Spinlocks
@ -331,7 +331,7 @@ A spinlock is a non-blocking lock. When a thread attempts to acquire a spinlock
#### References
The implementation code can be found at [openvela Spinlock](../../../../../../../open-vela/nuttx/tree/dev/include/nuttx/spinlock.h).
The implementation code can be found at [openvela Spinlock](../../../../../../../open-vela/nuttx/tree/trunk/include/nuttx/spinlock.h).
### 4. Atomic Operations
@ -350,7 +350,7 @@ Atomic operations guarantee that instructions execute indivisibly, meaning their
#### References
- For a detailed description of atomic operations, see the [Atomic Operations API](./resource_sync/atomic_operation.md).
- For related interface code, see [openvela atomic](../../../../../../../open-vela/nuttx/tree/dev/include/nuttx/atomic.h).
- For related interface code, see [openvela atomic](../../../../../../../open-vela/nuttx/tree/trunk/include/nuttx/atomic.h).
### 5. IRQ Control
@ -368,7 +368,7 @@ openvela implements interrupt masking for the local CPU via `up_irq_xxx()` funct
#### References
- For details on interrupt system adaptation, refer to the [Interrupt System Adaptation Guide](./../../chip_porting/Interrupt_System_Adaptation_Guide.md).
- For the interface code, see the [openvela irq interface](../../../../../../../open-vela/nuttx/tree/dev/include/nuttx/irq.h).
- For the interface code, see the [openvela irq interface](../../../../../../../open-vela/nuttx/tree/trunk/include/nuttx/irq.h).
### 6. Scheduler Control
@ -448,7 +448,7 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
#### References
For the implementation code, see [openvela sched_lock.c](../../../../../../../open-vela/nuttx/tree/dev/sched/sched/sched_lock.c) and [openvela sched_unlock.c](../../../../../../../open-vela/nuttx/tree/dev/sched/sched/sched_unlock.c).
For the implementation code, see [openvela sched_lock.c](../../../../../../../open-vela/nuttx/tree/trunk/sched/sched/sched_lock.c) and [openvela sched_unlock.c](../../../../../../../open-vela/nuttx/tree/trunk/sched/sched/sched_unlock.c).
### 7. Pthread Mutexes
@ -464,7 +464,7 @@ A mutex mechanism provided by the POSIX threads (Pthread) standard, intended exc
#### References
For the implementation code, see [openvela pthread](../../../../../../../open-vela/nuttx/tree/dev/libs/libc/pthread).
For the implementation code, see [openvela pthread](../../../../../../../open-vela/nuttx/tree/trunk/libs/libc/pthread).
### 8. Choosing a Synchronization Mechanism
@ -526,7 +526,7 @@ Work queues are particularly well-suited for the following scenarios:
#### References
- For a detailed description of work queues, refer to the [Work Queues](./IPC/work_queue.md).
- For the implementation code, see the [openvela wqueue](../../../../../../../open-vela/nuttx/tree/dev/sched/wqueue).
- For the implementation code, see the [openvela wqueue](../../../../../../../open-vela/nuttx/tree/trunk/sched/wqueue).
### 2. Message Queues
@ -552,7 +552,7 @@ Message queues are particularly well-suited for the following scenarios:
#### References
- For a detailed description of message queues, refer to the [Message Queues](./IPC/message_queue.md).
- For the implementation code, see the [openvela mqueue](../../../../../../../open-vela/nuttx/tree/dev/sched/mqueue) source.
- For the implementation code, see the [openvela mqueue](../../../../../../../open-vela/nuttx/tree/trunk/sched/mqueue) source.
### 3. Choosing a Communication Scheme
@ -572,4 +572,4 @@ When multi-threading is necessary, the following common schemes can be considere
## VIII. Examples
[OS Base Component Development Examples](./async_samples.md)
[OS Base Component Development Examples](./async_samples.md)

View File

@ -22,8 +22,8 @@ In cases where the compiler or target hardware lacks adequate support for atomic
Developers can control this behavior using the kernel configuration option `CONFIG_LIBC_ARCH_ATOMIC`. If this option is enabled, the system will link against the software emulation functions defined in `arch_atomic.c` instead of using the compiler's built-in functions.
- **Source Path**: [nuttx/libs/libc/machine/arch_atomic.c](../../../../../../../nuttx/blob/dev/libs/libc/machine/arch_atomic.c)
- **Related Build Configuration**: [nuttx/libs/libc/machine/Make.defs](../../../../../../../nuttx/blob/dev/libs/libc/machine/Make.defs)
- **Source Path**: [nuttx/libs/libc/machine/arch_atomic.c](../../../../../../../nuttx/blob/trunk/libs/libc/machine/arch_atomic.c)
- **Related Build Configuration**: [nuttx/libs/libc/machine/Make.defs](../../../../../../../nuttx/blob/trunk/libs/libc/machine/Make.defs)
## II. Usage

View File

@ -54,7 +54,7 @@ This mode is used for inter-task synchronization or communication.
- **Characteristics**:
- The operations to acquire (`wait`) and release (`post`) the semaphore are performed by **different tasks** (or a task and an ISR).
- **Priority inheritance must be disabled**. Otherwise, the task posting the semaphore (task B) might erroneously inherit the priority of the waiting task (task A), leading to unexpected scheduling behavior.
- If priority inheritance is enabled, and Task B has a lower priority than Task A, Task B's priority will be temporarily boosted to match that of Task A.
**Best Practice**: When initializing a semaphore, set the appropriate priority protocol using `sem_setprotocol()` based on its intended use.

View File

@ -131,7 +131,7 @@ void up_trigger_irq(int irq, cpu_set_t cpuset)
### 2. Interrupt-Related Macros to be Defined
In addition to the above function implementations, the manufacturer also needs to define a series of interrupt-related macros to describe the configuration of the NVIC (Nested Vectored Interrupt Controller). These macros need to be defined in the `chips/chip_name/include/irq.h` file. For reference, see the [RTL8720C example](../../../../../../../nuttx/blob/dev/arch/arm/src/rtl8720c/include/irq.h).
In addition to the above function implementations, the manufacturer also needs to define a series of interrupt-related macros to describe the configuration of the NVIC (Nested Vectored Interrupt Controller). These macros need to be defined in the `chips/chip_name/include/irq.h` file. For reference, see the [RTL8720C example](../../../../../../../nuttx/blob/trunk/arch/arm/src/rtl8720c/include/irq.h).
The following are the macros that must be implemented and their functional descriptions:

View File

@ -808,4 +808,4 @@ __cyg_profile_func_exit(void *this_fn, void *call_site)
// Exclude files whose paths contain "arch" or "board"
CFLAGS += -finstrument-functions-exclude-file-list=arch,board
```
```

Some files were not shown because too many files have changed in this diff Show More