├── .clang-format ├── .github └── workflows │ ├── build.yml │ ├── release.yml │ └── sponsors.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── NOTICE ├── README.md ├── docs ├── 1.x_to2.x_migration_guide.md ├── Bluetooth 5 features.md ├── Command_line_config.md ├── Doxyfile ├── Migration_guide.md ├── New_user_guide.md ├── Usage_tips.md └── index.md ├── examples ├── BLE_Beacon_Scanner │ ├── BLE_Beacon_Scanner.ino │ └── BLE_Beacon_Scanner.md ├── BLE_EddystoneTLM_Beacon │ ├── BLE_EddystoneTLM_Beacon.ino │ └── BLE_EddystoneTLM_Beacon.md ├── Bluetooth_5 │ ├── NimBLE_extended_client │ │ └── NimBLE_extended_client.ino │ ├── NimBLE_extended_scan │ │ └── NimBLE_extended_scan.ino │ ├── NimBLE_extended_server │ │ └── NimBLE_extended_server.ino │ └── NimBLE_multi_advertiser │ │ └── NimBLE_multi_advertiser.ino ├── L2CAP │ ├── L2CAP_Client │ │ └── L2CAP_Client.ino │ └── L2CAP_Server │ │ └── L2CAP_Server.ino ├── NimBLE_Async_Client │ └── NimBLE_Async_Client.ino ├── NimBLE_Client │ └── NimBLE_Client.ino ├── NimBLE_Scan_Continuous │ └── NimBLE_Scan_Continuous.ino ├── NimBLE_Scan_Whitelist │ └── NimBLE_Scan_whitelist.ino ├── NimBLE_Secure_Client │ └── NimBLE_Secure_Client.ino ├── NimBLE_Secure_Server │ └── NimBLE_Secure_Server.ino ├── NimBLE_Server │ └── NimBLE_Server.ino ├── NimBLE_Server_Whitelist │ └── NimBLE_Server_Whitelist.ino ├── NimBLE_active_passive_scan │ └── NimBLE_active_passive_scan.ino └── NimBLE_iBeacon │ └── NimBLE_iBeacon.ino ├── library.properties └── src ├── HIDKeyboardTypes.h ├── HIDTypes.h ├── NimBLE2904.cpp ├── NimBLE2904.h ├── NimBLEAddress.cpp ├── NimBLEAddress.h ├── NimBLEAdvertisedDevice.cpp ├── NimBLEAdvertisedDevice.h ├── NimBLEAdvertisementData.cpp ├── NimBLEAdvertisementData.h ├── NimBLEAdvertising.cpp ├── NimBLEAdvertising.h ├── NimBLEAttValue.cpp ├── NimBLEAttValue.h ├── NimBLEAttribute.h ├── NimBLEBeacon.cpp ├── NimBLEBeacon.h ├── NimBLECharacteristic.cpp ├── NimBLECharacteristic.h ├── NimBLEClient.cpp ├── NimBLEClient.h ├── NimBLEConnInfo.h ├── NimBLEDescriptor.cpp ├── NimBLEDescriptor.h ├── NimBLEDevice.cpp ├── NimBLEDevice.h ├── NimBLEEddystoneTLM.cpp ├── NimBLEEddystoneTLM.h ├── NimBLEExtAdvertising.cpp ├── NimBLEExtAdvertising.h ├── NimBLEHIDDevice.cpp ├── NimBLEHIDDevice.h ├── NimBLEL2CAPChannel.cpp ├── NimBLEL2CAPChannel.h ├── NimBLEL2CAPServer.cpp ├── NimBLEL2CAPServer.h ├── NimBLELocalAttribute.h ├── NimBLELocalValueAttribute.h ├── NimBLELog.h ├── NimBLERemoteCharacteristic.cpp ├── NimBLERemoteCharacteristic.h ├── NimBLERemoteDescriptor.cpp ├── NimBLERemoteDescriptor.h ├── NimBLERemoteService.cpp ├── NimBLERemoteService.h ├── NimBLERemoteValueAttribute.cpp ├── NimBLERemoteValueAttribute.h ├── NimBLEScan.cpp ├── NimBLEScan.h ├── NimBLEServer.cpp ├── NimBLEServer.h ├── NimBLEService.cpp ├── NimBLEService.h ├── NimBLEUUID.cpp ├── NimBLEUUID.h ├── NimBLEUtils.cpp ├── NimBLEUtils.h ├── NimBLEValueAttribute.h ├── nimble ├── CODING_STANDARDS.md ├── LICENSE ├── NOTICE ├── README.md ├── RELEASE_NOTES.md ├── console │ └── console.h ├── esp_port │ ├── esp-hci │ │ ├── include │ │ │ └── esp_nimble_hci.h │ │ └── src │ │ │ ├── esp_nimble_hci.c │ │ │ ├── na_hci_driver.c │ │ │ └── na_hci_transport.c │ └── port │ │ ├── include │ │ ├── bt_osi_mem.h │ │ ├── esp_nimble_cfg.h │ │ └── esp_nimble_mem.h │ │ ├── src │ │ └── exp_nimble_mem.c │ │ └── transport │ │ └── include │ │ ├── esp_hci_driver.h │ │ ├── esp_hci_internal.h │ │ └── esp_hci_transport.h ├── ext │ └── tinycrypt │ │ ├── AUTHORS │ │ ├── LICENSE │ │ ├── README │ │ ├── VERSION │ │ ├── include │ │ └── tinycrypt │ │ │ ├── aes.h │ │ │ ├── cbc_mode.h │ │ │ ├── ccm_mode.h │ │ │ ├── cmac_mode.h │ │ │ ├── constants.h │ │ │ ├── ctr_mode.h │ │ │ ├── ctr_prng.h │ │ │ ├── ecc.h │ │ │ ├── ecc_dh.h │ │ │ ├── ecc_dsa.h │ │ │ ├── ecc_platform_specific.h │ │ │ ├── hmac.h │ │ │ ├── hmac_prng.h │ │ │ ├── sha256.h │ │ │ └── utils.h │ │ └── src │ │ ├── aes_decrypt.c │ │ ├── aes_encrypt.c │ │ ├── cbc_mode.c │ │ ├── ccm_mode.c │ │ ├── cmac_mode.c │ │ ├── ctr_mode.c │ │ ├── ctr_prng.c │ │ ├── ecc.c │ │ ├── ecc_dh.c │ │ ├── ecc_dsa.c │ │ ├── ecc_platform_specific.c │ │ ├── hmac.c │ │ ├── hmac_prng.c │ │ ├── sha256.c │ │ └── utils.c ├── nimble │ ├── controller │ │ ├── include │ │ │ └── controller │ │ │ │ ├── ble_fem.h │ │ │ │ ├── ble_hw.h │ │ │ │ ├── ble_ll.h │ │ │ │ ├── ble_ll_adv.h │ │ │ │ ├── ble_ll_conn.h │ │ │ │ ├── ble_ll_crypto.h │ │ │ │ ├── ble_ll_ctrl.h │ │ │ │ ├── ble_ll_ext.h │ │ │ │ ├── ble_ll_hci.h │ │ │ │ ├── ble_ll_iso.h │ │ │ │ ├── ble_ll_iso_big.h │ │ │ │ ├── ble_ll_isoal.h │ │ │ │ ├── ble_ll_pdu.h │ │ │ │ ├── ble_ll_resolv.h │ │ │ │ ├── ble_ll_rfmgmt.h │ │ │ │ ├── ble_ll_scan.h │ │ │ │ ├── ble_ll_scan_aux.h │ │ │ │ ├── ble_ll_sched.h │ │ │ │ ├── ble_ll_sync.h │ │ │ │ ├── ble_ll_tmr.h │ │ │ │ ├── ble_ll_trace.h │ │ │ │ ├── ble_ll_utils.h │ │ │ │ ├── ble_ll_whitelist.h │ │ │ │ ├── ble_phy.h │ │ │ │ └── ble_phy_trace.h │ │ └── src │ │ │ ├── ble_ll.c │ │ │ ├── ble_ll_adv.c │ │ │ ├── ble_ll_conn.c │ │ │ ├── ble_ll_conn_hci.c │ │ │ ├── ble_ll_conn_priv.h │ │ │ ├── ble_ll_crypto.c │ │ │ ├── ble_ll_ctrl.c │ │ │ ├── ble_ll_ctrl_priv.h │ │ │ ├── ble_ll_dtm.c │ │ │ ├── ble_ll_dtm_priv.h │ │ │ ├── ble_ll_hci.c │ │ │ ├── ble_ll_hci_ev.c │ │ │ ├── ble_ll_hci_priv.h │ │ │ ├── ble_ll_hci_supp_cmd.c │ │ │ ├── ble_ll_hci_vs.c │ │ │ ├── ble_ll_iso.c │ │ │ ├── ble_ll_iso_big.c │ │ │ ├── ble_ll_isoal.c │ │ │ ├── ble_ll_pdu.c │ │ │ ├── ble_ll_priv.h │ │ │ ├── ble_ll_rand.c │ │ │ ├── ble_ll_resolv.c │ │ │ ├── ble_ll_rfmgmt.c │ │ │ ├── ble_ll_scan.c │ │ │ ├── ble_ll_scan_aux.c │ │ │ ├── ble_ll_sched.c │ │ │ ├── ble_ll_sync.c │ │ │ ├── ble_ll_trace.c │ │ │ ├── ble_ll_utils.c │ │ │ └── ble_ll_whitelist.c │ ├── drivers │ │ ├── nrf51 │ │ │ ├── include │ │ │ │ └── ble │ │ │ │ │ └── xcvr.h │ │ │ └── src │ │ │ │ ├── ble_hw.c │ │ │ │ └── ble_phy.c │ │ └── nrf5x │ │ │ ├── include │ │ │ └── ble │ │ │ │ └── xcvr.h │ │ │ └── src │ │ │ ├── ble_hw.c │ │ │ ├── ble_phy.c │ │ │ ├── ble_phy_trace.c │ │ │ ├── nrf52 │ │ │ ├── phy.c │ │ │ └── phy_ppi.h │ │ │ ├── nrf53 │ │ │ ├── phy.c │ │ │ └── phy_ppi.h │ │ │ └── phy_priv.h │ ├── host │ │ ├── include │ │ │ └── host │ │ │ │ ├── ble_aes_ccm.h │ │ │ │ ├── ble_att.h │ │ │ │ ├── ble_dtm.h │ │ │ │ ├── ble_ead.h │ │ │ │ ├── ble_eddystone.h │ │ │ │ ├── ble_esp_gap.h │ │ │ │ ├── ble_esp_gatt.h │ │ │ │ ├── ble_esp_hs.h │ │ │ │ ├── ble_gap.h │ │ │ │ ├── ble_gatt.h │ │ │ │ ├── ble_hs.h │ │ │ │ ├── ble_hs_adv.h │ │ │ │ ├── ble_hs_hci.h │ │ │ │ ├── ble_hs_id.h │ │ │ │ ├── ble_hs_log.h │ │ │ │ ├── ble_hs_mbuf.h │ │ │ │ ├── ble_hs_pvcy.h │ │ │ │ ├── ble_hs_stop.h │ │ │ │ ├── ble_ibeacon.h │ │ │ │ ├── ble_l2cap.h │ │ │ │ ├── ble_sm.h │ │ │ │ ├── ble_store.h │ │ │ │ └── ble_uuid.h │ │ ├── mesh │ │ │ ├── include │ │ │ │ └── mesh │ │ │ │ │ ├── access.h │ │ │ │ │ ├── atomic.h │ │ │ │ │ ├── cdb.h │ │ │ │ │ ├── cfg.h │ │ │ │ │ ├── cfg_cli.h │ │ │ │ │ ├── cfg_srv.h │ │ │ │ │ ├── glue.h │ │ │ │ │ ├── health_cli.h │ │ │ │ │ ├── health_srv.h │ │ │ │ │ ├── heartbeat.h │ │ │ │ │ ├── main.h │ │ │ │ │ ├── mesh.h │ │ │ │ │ ├── model_cli.h │ │ │ │ │ ├── model_srv.h │ │ │ │ │ ├── msg.h │ │ │ │ │ ├── porting.h │ │ │ │ │ ├── proxy.h │ │ │ │ │ ├── slist.h │ │ │ │ │ └── testing.h │ │ │ └── src │ │ │ │ ├── access.c │ │ │ │ ├── access.h │ │ │ │ ├── adv.c │ │ │ │ ├── adv.h │ │ │ │ ├── adv_ext.c │ │ │ │ ├── adv_legacy.c │ │ │ │ ├── aes-ccm.c │ │ │ │ ├── app_keys.c │ │ │ │ ├── app_keys.h │ │ │ │ ├── atomic.h │ │ │ │ ├── beacon.c │ │ │ │ ├── beacon.h │ │ │ │ ├── cdb.c │ │ │ │ ├── cdb_priv.h │ │ │ │ ├── cfg.c │ │ │ │ ├── cfg.h │ │ │ │ ├── cfg_cli.c │ │ │ │ ├── cfg_srv.c │ │ │ │ ├── crypto.c │ │ │ │ ├── crypto.h │ │ │ │ ├── foundation.h │ │ │ │ ├── friend.c │ │ │ │ ├── friend.h │ │ │ │ ├── glue.c │ │ │ │ ├── health_cli.c │ │ │ │ ├── health_srv.c │ │ │ │ ├── heartbeat.c │ │ │ │ ├── heartbeat.h │ │ │ │ ├── light_model.c │ │ │ │ ├── light_model.h │ │ │ │ ├── lpn.c │ │ │ │ ├── lpn.h │ │ │ │ ├── mesh.c │ │ │ │ ├── mesh_priv.h │ │ │ │ ├── model_cli.c │ │ │ │ ├── model_srv.c │ │ │ │ ├── msg.c │ │ │ │ ├── net.c │ │ │ │ ├── net.h │ │ │ │ ├── pb_adv.c │ │ │ │ ├── pb_gatt.c │ │ │ │ ├── pb_gatt_srv.c │ │ │ │ ├── pb_gatt_srv.h │ │ │ │ ├── prov.c │ │ │ │ ├── prov.h │ │ │ │ ├── prov_bearer.h │ │ │ │ ├── prov_device.c │ │ │ │ ├── provisioner.c │ │ │ │ ├── provisioner.h │ │ │ │ ├── proxy.c │ │ │ │ ├── proxy.h │ │ │ │ ├── proxy_msg.c │ │ │ │ ├── proxy_msg.h │ │ │ │ ├── proxy_srv.c │ │ │ │ ├── rpl.c │ │ │ │ ├── rpl.h │ │ │ │ ├── settings.c │ │ │ │ ├── settings.h │ │ │ │ ├── shell.c │ │ │ │ ├── shell.h │ │ │ │ ├── subnet.c │ │ │ │ ├── subnet.h │ │ │ │ ├── testing.c │ │ │ │ ├── testing.h │ │ │ │ ├── transport.c │ │ │ │ └── transport.h │ │ ├── services │ │ │ ├── gap │ │ │ │ ├── include │ │ │ │ │ └── services │ │ │ │ │ │ └── gap │ │ │ │ │ │ └── ble_svc_gap.h │ │ │ │ └── src │ │ │ │ │ └── ble_svc_gap.c │ │ │ └── gatt │ │ │ │ ├── include │ │ │ │ └── services │ │ │ │ │ └── gatt │ │ │ │ │ └── ble_svc_gatt.h │ │ │ │ └── src │ │ │ │ └── ble_svc_gatt.c │ │ ├── src │ │ │ ├── ble_aes_ccm.c │ │ │ ├── ble_att.c │ │ │ ├── ble_att_clt.c │ │ │ ├── ble_att_cmd.c │ │ │ ├── ble_att_cmd_priv.h │ │ │ ├── ble_att_priv.h │ │ │ ├── ble_att_svr.c │ │ │ ├── ble_dtm.c │ │ │ ├── ble_ead.c │ │ │ ├── ble_eatt.c │ │ │ ├── ble_eatt_priv.h │ │ │ ├── ble_eddystone.c │ │ │ ├── ble_gap.c │ │ │ ├── ble_gap_priv.h │ │ │ ├── ble_gatt_priv.h │ │ │ ├── ble_gattc.c │ │ │ ├── ble_gattc_cache.c │ │ │ ├── ble_gattc_cache_conn.c │ │ │ ├── ble_gattc_cache_priv.h │ │ │ ├── ble_gatts.c │ │ │ ├── ble_gatts_lcl.c │ │ │ ├── ble_hs.c │ │ │ ├── ble_hs_adv.c │ │ │ ├── ble_hs_adv_priv.h │ │ │ ├── ble_hs_atomic.c │ │ │ ├── ble_hs_atomic_priv.h │ │ │ ├── ble_hs_cfg.c │ │ │ ├── ble_hs_conn.c │ │ │ ├── ble_hs_conn_priv.h │ │ │ ├── ble_hs_flow.c │ │ │ ├── ble_hs_flow_priv.h │ │ │ ├── ble_hs_hci.c │ │ │ ├── ble_hs_hci_cmd.c │ │ │ ├── ble_hs_hci_evt.c │ │ │ ├── ble_hs_hci_priv.h │ │ │ ├── ble_hs_hci_util.c │ │ │ ├── ble_hs_id.c │ │ │ ├── ble_hs_id_priv.h │ │ │ ├── ble_hs_log.c │ │ │ ├── ble_hs_mbuf.c │ │ │ ├── ble_hs_mbuf_priv.h │ │ │ ├── ble_hs_misc.c │ │ │ ├── ble_hs_mqueue.c │ │ │ ├── ble_hs_periodic_sync.c │ │ │ ├── ble_hs_periodic_sync_priv.h │ │ │ ├── ble_hs_priv.h │ │ │ ├── ble_hs_pvcy.c │ │ │ ├── ble_hs_pvcy_priv.h │ │ │ ├── ble_hs_resolv.c │ │ │ ├── ble_hs_resolv_priv.h │ │ │ ├── ble_hs_shutdown.c │ │ │ ├── ble_hs_startup.c │ │ │ ├── ble_hs_startup_priv.h │ │ │ ├── ble_hs_stop.c │ │ │ ├── ble_ibeacon.c │ │ │ ├── ble_l2cap.c │ │ │ ├── ble_l2cap_coc.c │ │ │ ├── ble_l2cap_coc_priv.h │ │ │ ├── ble_l2cap_priv.h │ │ │ ├── ble_l2cap_sig.c │ │ │ ├── ble_l2cap_sig_cmd.c │ │ │ ├── ble_l2cap_sig_priv.h │ │ │ ├── ble_sm.c │ │ │ ├── ble_sm_alg.c │ │ │ ├── ble_sm_cmd.c │ │ │ ├── ble_sm_lgcy.c │ │ │ ├── ble_sm_priv.h │ │ │ ├── ble_sm_sc.c │ │ │ ├── ble_store.c │ │ │ ├── ble_store_util.c │ │ │ ├── ble_uuid.c │ │ │ └── ble_uuid_priv.h │ │ ├── store │ │ │ ├── config │ │ │ │ ├── include │ │ │ │ │ └── store │ │ │ │ │ │ └── config │ │ │ │ │ │ └── ble_store_config.h │ │ │ │ └── src │ │ │ │ │ ├── ble_store_config.c │ │ │ │ │ ├── ble_store_config_conf.c │ │ │ │ │ ├── ble_store_config_priv.h │ │ │ │ │ └── ble_store_nvs.c │ │ │ └── ram │ │ │ │ ├── include │ │ │ │ └── store │ │ │ │ │ └── ram │ │ │ │ │ └── ble_store_ram.h │ │ │ │ └── src │ │ │ │ └── ble_store_ram.c │ │ └── util │ │ │ ├── include │ │ │ └── host │ │ │ │ └── util │ │ │ │ └── util.h │ │ │ └── src │ │ │ └── addr.c │ ├── include │ │ └── nimble │ │ │ ├── ble.h │ │ │ ├── hci_common.h │ │ │ ├── nimble_npl.h │ │ │ ├── nimble_opt.h │ │ │ └── nimble_opt_auto.h │ └── transport │ │ ├── common │ │ ├── hci_h4 │ │ │ ├── include │ │ │ │ └── nimble │ │ │ │ │ └── transport │ │ │ │ │ └── hci_h4.h │ │ │ └── src │ │ │ │ └── hci_h4.c │ │ └── hci_ipc │ │ │ ├── include │ │ │ └── nimble │ │ │ │ └── transport │ │ │ │ └── hci_ipc.h │ │ │ └── src │ │ │ └── hci_ipc.c │ │ ├── esp_ipc │ │ └── src │ │ │ └── hci_esp_ipc.c │ │ ├── esp_ipc_legacy │ │ └── src │ │ │ └── hci_esp_ipc_legacy.c │ │ ├── include │ │ └── nimble │ │ │ ├── transport.h │ │ │ ├── transport │ │ │ ├── monitor.h │ │ │ └── transport_ipc.h │ │ │ └── transport_impl.h │ │ ├── nrf5340 │ │ └── src │ │ │ └── nrf5340_ble_hci.c │ │ └── src │ │ └── transport.c └── porting │ ├── nimble │ ├── include │ │ ├── hal │ │ │ ├── hal_gpio.h │ │ │ ├── hal_os_tick.h │ │ │ ├── hal_system.h │ │ │ ├── hal_timer.h │ │ │ ├── hal_uart.h │ │ │ └── hal_watchdog.h │ │ ├── log │ │ │ └── log.h │ │ ├── log_common │ │ │ ├── ignore.h │ │ │ └── log_common.h │ │ ├── logcfg │ │ │ └── logcfg.h │ │ ├── mem │ │ │ └── mem.h │ │ ├── modlog │ │ │ └── modlog.h │ │ ├── nimble │ │ │ ├── nimble_port.h │ │ │ └── storage_port.h │ │ ├── os │ │ │ ├── endian.h │ │ │ ├── os.h │ │ │ ├── os_cputime.h │ │ │ ├── os_error.h │ │ │ ├── os_mbuf.h │ │ │ ├── os_mempool.h │ │ │ ├── os_trace_api.h │ │ │ ├── queue.h │ │ │ └── util.h │ │ ├── stats │ │ │ └── stats.h │ │ ├── syscfg │ │ │ └── syscfg.h │ │ ├── sysflash │ │ │ └── sysflash.h │ │ └── sysinit │ │ │ └── sysinit.h │ └── src │ │ ├── endian.c │ │ ├── hal_timer.c │ │ ├── mem.c │ │ ├── nimble_port.c │ │ ├── os_cputime.c │ │ ├── os_cputime_pwr2.c │ │ ├── os_mbuf.c │ │ ├── os_mempool.c │ │ └── os_msys_init.c │ └── npl │ └── freertos │ ├── include │ └── nimble │ │ ├── nimble_npl_os.h │ │ ├── nimble_port_freertos.h │ │ └── npl_freertos.h │ └── src │ ├── nimble_port_freertos.c │ └── npl_os_freertos.c ├── nimconfig.h ├── nimconfig_rename.h └── syscfg └── syscfg.h /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | Language: Cpp 3 | ColumnLimit: 120 4 | IndentWidth: 4 5 | TabWidth: 4 6 | UseTab: Never 7 | SortIncludes: Never 8 | PPIndentWidth : 1 9 | IndentPPDirectives: AfterHash 10 | ReflowComments: true 11 | SpacesBeforeTrailingComments: 1 12 | AlignTrailingComments: true 13 | AlignAfterOpenBracket: Align 14 | AlignConsecutiveMacros: 15 | Enabled: true 16 | AcrossEmptyLines: true 17 | AcrossComments: true 18 | AlignConsecutiveAssignments: 19 | Enabled: true 20 | AcrossEmptyLines: false 21 | AcrossComments: true 22 | AlignCompound: true 23 | PadOperators: true 24 | AlignConsecutiveDeclarations: 25 | Enabled: true 26 | AcrossEmptyLines: false 27 | AcrossComments: true 28 | AlignEscapedNewlines: Left 29 | AccessModifierOffset: -2 30 | AlignArrayOfStructures: Right 31 | AlignOperands: Align 32 | AllowAllArgumentsOnNextLine: false 33 | AllowShortFunctionsOnASingleLine: Inline 34 | AllowShortBlocksOnASingleLine: Empty 35 | BreakBeforeBinaryOperators: None 36 | BinPackArguments: false 37 | BinPackParameters: false 38 | DerivePointerAlignment: false 39 | PenaltyBreakAssignment: 4 40 | PenaltyExcessCharacter: 4 41 | PenaltyBreakBeforeFirstCallParameter: 1 42 | PointerAlignment: Left 43 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | build_docs: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - name: Doxygen Action 14 | uses: mattnotmitt/doxygen-action@v1.9.8 15 | with: 16 | working-directory: 'docs/' 17 | 18 | - name: Deploy 19 | uses: peaceiris/actions-gh-pages@v4 20 | with: 21 | github_token: ${{ secrets.GITHUB_TOKEN }} 22 | publish_dir: ./docs/doxydocs/html -------------------------------------------------------------------------------- /.github/workflows/sponsors.yml: -------------------------------------------------------------------------------- 1 | name: Generate Sponsors README 2 | on: 3 | workflow_dispatch: 4 | permissions: 5 | contents: write 6 | jobs: 7 | deploy: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 🛎️ 11 | uses: actions/checkout@v4 12 | 13 | - name: Generate Sponsors 💖 14 | uses: JamesIves/github-sponsors-readme-action@v1.5.4 15 | with: 16 | token: ${{ secrets.PAT }} 17 | file: 'README.md' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | docs/doxydocs 2 | .development 3 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | esp-nimble-cpp 2 | NimBLE-Arduino 3 | Copyright 2020-2025 Ryan Powell and 4 | esp-nimble-cpp, NimBLE-Arduino contributors. 5 | 6 | The Initial Developer of some parts of this library, which are copied from, 7 | derived from, or inspired by is, esp32-snippets, Copyright 2017 Neil Kolban. 8 | 9 | If this library is used for commercial purposes, it is requested that the user consider 10 | making a donation and/or sponsoring this project to support it's ongoing development. 11 | -------------------------------------------------------------------------------- /docs/Bluetooth 5 features.md: -------------------------------------------------------------------------------- 1 | # Bluetooth 5.x features 2 | 3 | ## About extended advertising 4 | Extended advertising allows for much more capability and flexibility. 5 | 6 | * Allows for 251 bytes of advertisement data and up to 1650 bytes when chained (configuration dependant) vs 31. 7 | 8 | * New PHY's (physical layers) that allow for faster data rate (2M PHY) or long range/slower data rates (CODED PHY) as well as the original 1M PHY. 9 | 10 | * New periodic advertising, allowing the scanning device to sync with the advertisements of a beacon. This allows for the scanning device to sleep or perform other tasks before the next expected advertisement is sent, preserving cpu cycles and power (To be implemented). 11 |
12 | 13 | ## Enabling extended advertising 14 | Extended advertising is supported when enabled with the config option `CONFIG_BT_NIMBLE_EXT_ADV` set to a value of 1. This is done in menuconfig under `Component config > Bluetooth > NimBLE options > Enable extended advertising`, or set in `nimconfig.h` for Arduino, or in `build_flags` in PlatformIO. 15 | 16 | When enabled the following will occur: 17 | * `NimBLEScan::start` method will scan on both the 1M PHY and the coded PHY standards automatically. 18 | 19 | * `NimBLEClient::connect` will use the primary PHY the device is listening on, unless specified (see below). 20 | 21 | * `NimBLEClient::setConnectPhy` becomes available to specify the PHY's to connect with (default is all). 22 | 23 | * `NimBLEAdvertising` is no longer available for use and is replaced by `NimBLEExtAdvertising`. `NimBLEDevice::getAdvertising` will now return an instance of `NimBLEExtAdvertising`. 24 | 25 | * `NimBLEAdvertisementData` is no longer available for use and is replaced by `NimBLEExtAdvertisement`. This new class is where everything about the advertisement is configured, including the advertisement intervals and advertisement ended callback. 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/BLE_Beacon_Scanner/BLE_Beacon_Scanner.md: -------------------------------------------------------------------------------- 1 | ## BLE Beacon Scanner 2 | 3 | Initiates a BLE device scan. 4 | Checks if the discovered devices are 5 | - an iBeacon 6 | - an Eddystone TLM beacon 7 | 8 | and sends the decoded beacon information over Serial log -------------------------------------------------------------------------------- /examples/BLE_EddystoneTLM_Beacon/BLE_EddystoneTLM_Beacon.md: -------------------------------------------------------------------------------- 1 | ## Eddystone TLM beacon 2 | EddystoneTLM beacon by BeeGee based on 3 | [pcbreflux ESP32 Eddystone TLM deepsleep](https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_Eddystone_TLM_deepsleep/ESP32_Eddystone_TLM_deepsleep.ino) 4 | 5 | [EddystoneTLM frame specification](https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md) 6 | 7 | Create a BLE server that will send periodic Eddystone TLM frames. 8 | The design of creating the BLE server is: 9 | 1. Create a BLE Server 10 | 2. Create advertising data 11 | 3. Start advertising. 12 | 4. wait 13 | 5. Stop advertising. 14 | 6. deep sleep 15 | -------------------------------------------------------------------------------- /examples/NimBLE_Scan_Continuous/NimBLE_Scan_Continuous.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Continuous Scan Example 3 | * 4 | * This example demonstrates how to continuously scan for BLE devices. 5 | * When devices are found the onDiscovered and onResults callbacks will be called with the device data. 6 | * The scan will not store the results, only the callbacks will be used 7 | * When the scan timeout is reached the onScanEnd callback will be called and the scan will be restarted. 8 | * This will clear the duplicate cache in the controller and allow the same devices to be reported again. 9 | * 10 | * Created: on March 24 2020 11 | * Author: H2zero 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | static constexpr uint32_t scanTimeMs = 30 * 1000; // 30 seconds scan time. 18 | 19 | class scanCallbacks : public NimBLEScanCallbacks { 20 | /** Initial discovery, advertisement data only. */ 21 | void onDiscovered(const NimBLEAdvertisedDevice* advertisedDevice) override { 22 | printf("Discovered Device: %s\n", advertisedDevice->toString().c_str()); 23 | } 24 | 25 | /** 26 | * If active scanning the result here will have the scan response data. 27 | * If not active scanning then this will be the same as onDiscovered. 28 | */ 29 | void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override { 30 | printf("Device result: %s\n", advertisedDevice->toString().c_str()); 31 | } 32 | 33 | void onScanEnd(const NimBLEScanResults& results, int reason) override { 34 | printf("Scan ended reason = %d; restarting scan\n", reason); 35 | NimBLEDevice::getScan()->start(scanTimeMs, false, true); 36 | } 37 | } scanCallbacks; 38 | 39 | void setup() { 40 | NimBLEDevice::init(""); // Initialize the device, you can specify a device name if you want. 41 | NimBLEScan* pBLEScan = NimBLEDevice::getScan(); // Create the scan object. 42 | pBLEScan->setScanCallbacks(&scanCallbacks, false); // Set the callback for when devices are discovered, no duplicates. 43 | pBLEScan->setActiveScan(true); // Set active scanning, this will get more data from the advertiser. 44 | pBLEScan->setMaxResults(0); // Do not store the scan results, use callback only. 45 | pBLEScan->start(scanTimeMs, false, true); // duration, not a continuation of last scan, restart to get all devices again. 46 | printf("Scanning...\n"); 47 | } 48 | 49 | void loop() {} 50 | -------------------------------------------------------------------------------- /examples/NimBLE_Scan_Whitelist/NimBLE_Scan_whitelist.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * NimBLE_Scan_Whitelist demo 3 | * 4 | * Created May 16, 2021 5 | * Author: h2zero 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | int scanTimeMs = 5 * 1000; // In milliseconds, 0 = scan forever 12 | NimBLEScan* pBLEScan; 13 | 14 | class ScanCallbacks : public NimBLEScanCallbacks { 15 | void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override { 16 | Serial.printf("Advertised Device: %s \n", advertisedDevice->toString().c_str()); 17 | /* 18 | * Here we add the device scanned to the whitelist based on service data but any 19 | * advertised data can be used for your preferred data. 20 | */ 21 | if (advertisedDevice->haveServiceData()) { 22 | /* If this is a device with data we want to capture, add it to the whitelist */ 23 | if (advertisedDevice->getServiceData(NimBLEUUID("AABB")) != "") { 24 | Serial.printf("Adding %s to whitelist\n", std::string(advertisedDevice->getAddress()).c_str()); 25 | NimBLEDevice::whiteListAdd(advertisedDevice->getAddress()); 26 | } 27 | } 28 | } 29 | } scanCallbacks; 30 | 31 | void setup() { 32 | Serial.begin(115200); 33 | Serial.println("Scanning..."); 34 | 35 | NimBLEDevice::init(""); 36 | pBLEScan = NimBLEDevice::getScan(); 37 | pBLEScan->setScanCallbacks(&scanCallbacks); 38 | pBLEScan->setActiveScan(true); 39 | pBLEScan->setInterval(100); 40 | pBLEScan->setFilterPolicy(BLE_HCI_SCAN_FILT_NO_WL); 41 | pBLEScan->setWindow(99); 42 | } 43 | 44 | void loop() { 45 | NimBLEScanResults foundDevices = pBLEScan->getResults(scanTimeMs, false); 46 | Serial.print("Devices found: "); 47 | Serial.println(foundDevices.getCount()); 48 | Serial.println("Scan done!"); 49 | 50 | Serial.println("Whitelist contains:"); 51 | for (auto i = 0; i < NimBLEDevice::getWhiteListCount(); ++i) { 52 | Serial.println(NimBLEDevice::getWhiteListAddress(i).toString().c_str()); 53 | } 54 | 55 | /* 56 | * If we have addresses in the whitelist enable the filter unless no devices were found 57 | * then scan without so we can find any new devices that we want. 58 | */ 59 | if (NimBLEDevice::getWhiteListCount() > 0) { 60 | if (foundDevices.getCount() == 0) { 61 | pBLEScan->setFilterPolicy(BLE_HCI_SCAN_FILT_NO_WL); 62 | } else { 63 | pBLEScan->setFilterPolicy(BLE_HCI_SCAN_FILT_USE_WL); 64 | } 65 | } 66 | 67 | pBLEScan->clearResults(); 68 | delay(2000); 69 | } 70 | -------------------------------------------------------------------------------- /examples/NimBLE_Secure_Server/NimBLE_Secure_Server.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * NimBLE_Secure_Server Demo: 3 | * 4 | * This example demonstrates the secure passkey protected conenction and communication between an esp32 server and an 5 | * esp32 client. Please note that esp32 stores auth info in nvs memory. After a successful connection it is possible 6 | * that a passkey change will be ineffective. To avoid this clear the memory of the esp32's between security testings. 7 | * esptool.py is capable of this, example: esptool.py --port /dev/ttyUSB0 erase_flash. 8 | * 9 | * Created: on Jan 08 2021 10 | * Author: mblasee 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | Serial.println("Starting NimBLE Server"); 19 | NimBLEDevice::init("NimBLE"); 20 | NimBLEDevice::setPower(3); /** +3db */ 21 | 22 | NimBLEDevice::setSecurityAuth(true, true, true); /** bonding, MITM, BLE secure connections */ 23 | NimBLEDevice::setSecurityPasskey(123456); 24 | NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); /** Display only passkey */ 25 | NimBLEServer* pServer = NimBLEDevice::createServer(); 26 | NimBLEService* pService = pServer->createService("ABCD"); 27 | NimBLECharacteristic* pNonSecureCharacteristic = pService->createCharacteristic("1234", NIMBLE_PROPERTY::READ); 28 | NimBLECharacteristic* pSecureCharacteristic = 29 | pService->createCharacteristic("1235", 30 | NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN); 31 | 32 | pService->start(); 33 | pNonSecureCharacteristic->setValue("Hello Non Secure BLE"); 34 | pSecureCharacteristic->setValue("Hello Secure BLE"); 35 | 36 | NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising(); 37 | pAdvertising->addServiceUUID("ABCD"); 38 | pAdvertising->start(); 39 | } 40 | 41 | void loop() {} 42 | -------------------------------------------------------------------------------- /examples/NimBLE_active_passive_scan/NimBLE_active_passive_scan.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * NimBLE Scan active/passive switching demo 3 | * 4 | * Demonstrates the use of the scan callbacks while alternating between passive and active scanning. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | int scanTime = 5 * 1000; // In milliseconds, 0 = scan forever 11 | NimBLEScan* pBLEScan; 12 | 13 | bool active = false; 14 | 15 | class ScanCallbacks : public NimBLEScanCallbacks { 16 | void onDiscovered(const NimBLEAdvertisedDevice* advertisedDevice) override { 17 | Serial.printf("Discovered Advertised Device: %s \n", advertisedDevice->toString().c_str()); 18 | } 19 | 20 | void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override { 21 | Serial.printf("Advertised Device Result: %s \n", advertisedDevice->toString().c_str()); 22 | } 23 | 24 | void onScanEnd(const NimBLEScanResults& results, int reason) override { 25 | Serial.print("Scan Ended; reason = "); 26 | Serial.println(reason); 27 | active = !active; 28 | pBLEScan->setActiveScan(active); 29 | Serial.printf("scan start, active = %u\n", active); 30 | pBLEScan->start(scanTime); 31 | } 32 | } scanCallbacks; 33 | 34 | void setup() { 35 | Serial.begin(115200); 36 | Serial.println("Scanning..."); 37 | 38 | NimBLEDevice::init("active-passive-scan"); 39 | pBLEScan = NimBLEDevice::getScan(); 40 | pBLEScan->setScanCallbacks(&scanCallbacks); 41 | pBLEScan->setActiveScan(active); 42 | pBLEScan->setInterval(100); 43 | pBLEScan->setWindow(100); 44 | pBLEScan->start(scanTime); 45 | } 46 | 47 | void loop() {} 48 | -------------------------------------------------------------------------------- /examples/NimBLE_iBeacon/NimBLE_iBeacon.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * iBeacon example 3 | * 4 | * This example demonstrates how to publish an Apple-compatible iBeacon 5 | * 6 | * Created: on May 26 2025 7 | * Author: lazd 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | // According to Apple, it's important to have a 100ms advertising time 15 | #define BEACON_ADVERTISING_TIME 160 // 100ms 16 | 17 | // Hey, you! Replace this with your own unique UUID with something like https://www.uuidgenerator.net/ 18 | const char* iBeaconUUID = "26D0814C-F81C-4B2D-AC57-032E2AFF8642"; 19 | 20 | void setup() { 21 | NimBLEDevice::init("NimBLEiBeacon"); 22 | 23 | // Create beacon object 24 | NimBLEBeacon beacon; 25 | beacon.setMajor(1); 26 | beacon.setMinor(1); 27 | beacon.setSignalPower(0xC5); // Optional 28 | beacon.setProximityUUID(BLEUUID(iBeaconUUID)); // Unlike Bluedroid, you do not need to reverse endianness here 29 | 30 | // Create advertisement data 31 | NimBLEAdvertisementData beaconAdvertisementData; 32 | beaconAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED 33 | beaconAdvertisementData.setManufacturerData(beacon.getData()); 34 | 35 | // Start advertising 36 | NimBLEAdvertising *advertising = NimBLEDevice::getAdvertising(); 37 | advertising->setAdvertisingInterval(BEACON_ADVERTISING_TIME); 38 | advertising->setAdvertisementData(beaconAdvertisementData); 39 | advertising->start(); 40 | } 41 | 42 | void loop() {} 43 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=NimBLE-Arduino 2 | version=2.3.0 3 | author=h2zero 4 | maintainer=Ryan Powell 5 | sentence=Bluetooth low energy (BLE) library for Arduino based on NimBLE. 6 | paragraph=A light-weight alternative to the original bluedroid based BLE library for esp32 and Nordic nRF5 devices (must use n-able-Arduino core). Uses 50% less flash space and approximately 100KB less ram with the same functionality. Nearly 100% compatible with existing application code, migration guide included. 7 | url=https://github.com/h2zero/NimBLE-Arduino 8 | category=Communication 9 | architectures=esp32,arm-ble 10 | includes=NimBLEDevice.h 11 | -------------------------------------------------------------------------------- /src/NimBLE2904.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "NimBLE2904.h" 19 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL 20 | 21 | NimBLE2904::NimBLE2904(NimBLECharacteristic* pChr) 22 | : NimBLEDescriptor(NimBLEUUID((uint16_t)0x2904), BLE_GATT_CHR_F_READ, sizeof(NimBLE2904Data), pChr) { 23 | setValue(m_data); 24 | } // NimBLE2904 25 | 26 | /** 27 | * @brief Set the description. 28 | * @param [in] description The description value to set. 29 | */ 30 | void NimBLE2904::setDescription(uint16_t description) { 31 | m_data.m_description = description; 32 | setValue(m_data); 33 | } // setDescription 34 | 35 | /** 36 | * @brief Set the exponent. 37 | * @param [in] exponent The exponent value to set. 38 | */ 39 | void NimBLE2904::setExponent(int8_t exponent) { 40 | m_data.m_exponent = exponent; 41 | setValue(m_data); 42 | } // setExponent 43 | 44 | /** 45 | * @brief Set the format. 46 | * @param [in] format The format value to set. 47 | */ 48 | void NimBLE2904::setFormat(uint8_t format) { 49 | m_data.m_format = format; 50 | setValue(m_data); 51 | } // setFormat 52 | 53 | /** 54 | * @brief Set the namespace. 55 | * @param [in] namespace_value The namespace value toset. 56 | */ 57 | void NimBLE2904::setNamespace(uint8_t namespace_value) { 58 | m_data.m_namespace = namespace_value; 59 | setValue(m_data); 60 | } // setNamespace 61 | 62 | /** 63 | * @brief Set the units for this value. 64 | * @param [in] unit The type of units of this characteristic as defined by assigned numbers. 65 | * @details See https://www.bluetooth.com/specifications/assigned-numbers/units 66 | */ 67 | void NimBLE2904::setUnit(uint16_t unit) { 68 | m_data.m_unit = unit; 69 | setValue(m_data); 70 | } // setUnit 71 | 72 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL 73 | -------------------------------------------------------------------------------- /src/NimBLEAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_ADDRESS_H_ 19 | #define NIMBLE_CPP_ADDRESS_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED 23 | 24 | # if defined(CONFIG_NIMBLE_CPP_IDF) 25 | # include "nimble/ble.h" 26 | # else 27 | # include "nimble/nimble/include/nimble/ble.h" 28 | # endif 29 | 30 | /**** FIX COMPILATION ****/ 31 | # undef min 32 | # undef max 33 | /**************************/ 34 | 35 | # include 36 | 37 | /** 38 | * @brief A BLE device address. 39 | * 40 | * Every BLE device has a unique address which can be used to identify it and form connections. 41 | */ 42 | class NimBLEAddress : private ble_addr_t { 43 | public: 44 | /** 45 | * @brief Create a blank address, i.e. 00:00:00:00:00:00, type 0. 46 | */ 47 | NimBLEAddress() = default; 48 | NimBLEAddress(const ble_addr_t address); 49 | NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type); 50 | NimBLEAddress(const std::string& stringAddress, uint8_t type); 51 | NimBLEAddress(const uint64_t& address, uint8_t type); 52 | 53 | bool isRpa() const; 54 | bool isNrpa() const; 55 | bool isStatic() const; 56 | bool isPublic() const; 57 | bool isNull() const; 58 | bool equals(const NimBLEAddress& otherAddress) const; 59 | const ble_addr_t* getBase() const; 60 | std::string toString() const; 61 | uint8_t getType() const; 62 | const uint8_t* getVal() const; 63 | const NimBLEAddress& reverseByteOrder(); 64 | bool operator==(const NimBLEAddress& rhs) const; 65 | bool operator!=(const NimBLEAddress& rhs) const; 66 | operator std::string() const; 67 | operator uint64_t() const; 68 | }; 69 | 70 | #endif // CONFIG_BT_ENABLED 71 | #endif // NIMBLE_CPP_ADDRESS_H_ 72 | -------------------------------------------------------------------------------- /src/NimBLEAttribute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_ATTRIBUTE_H_ 19 | #define NIMBLE_CPP_ATTRIBUTE_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED && (CONFIG_BT_NIMBLE_ROLE_PERIPHERAL || CONFIG_BT_NIMBLE_ROLE_CENTRAL) 23 | 24 | # include "NimBLEUUID.h" 25 | 26 | /** 27 | * @brief A base class for BLE attributes. 28 | */ 29 | class NimBLEAttribute { 30 | public: 31 | /** 32 | * @brief Get the UUID of the attribute. 33 | * @return The UUID. 34 | */ 35 | const NimBLEUUID& getUUID() const { return m_uuid; } 36 | 37 | /** 38 | * @brief Get the handle of the attribute. 39 | */ 40 | uint16_t getHandle() const { return m_handle; }; 41 | 42 | protected: 43 | /** 44 | * @brief Construct a new NimBLEAttribute object. 45 | * @param [in] handle The handle of the attribute. 46 | * @param [in] uuid The UUID of the attribute. 47 | */ 48 | NimBLEAttribute(const NimBLEUUID& uuid, uint16_t handle) : m_uuid{uuid}, m_handle{handle} {} 49 | 50 | /** 51 | * @brief Destroy the NimBLEAttribute object. 52 | */ 53 | ~NimBLEAttribute() = default; 54 | 55 | const NimBLEUUID m_uuid{}; 56 | uint16_t m_handle{0}; 57 | }; 58 | 59 | #endif // CONFIG_BT_ENABLED && (CONFIG_BT_NIMBLE_ROLE_PERIPHERAL || CONFIG_BT_NIMBLE_ROLE_CENTRAL) 60 | #endif // NIMBLE_CPP_ATTRIBUTE_H_ 61 | -------------------------------------------------------------------------------- /src/NimBLEBeacon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_BEACON_H_ 19 | #define NIMBLE_CPP_BEACON_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER 23 | 24 | class NimBLEUUID; 25 | 26 | # include 27 | # include 28 | 29 | /** 30 | * @brief Representation of a beacon. 31 | * See: 32 | * * https://en.wikipedia.org/wiki/IBeacon 33 | */ 34 | class NimBLEBeacon { 35 | public: 36 | struct BeaconData { 37 | uint16_t manufacturerId{0x4c00}; 38 | uint8_t subType{0x02}; 39 | uint8_t subTypeLength{0x15}; 40 | uint8_t proximityUUID[16]{}; 41 | uint16_t major{}; 42 | uint16_t minor{}; 43 | int8_t signalPower{}; 44 | operator std::vector () const { 45 | return std::vector(reinterpret_cast(this), 46 | reinterpret_cast(this) + sizeof(BeaconData)); 47 | } 48 | } __attribute__((packed)); 49 | 50 | const BeaconData& getData(); 51 | uint16_t getMajor(); 52 | uint16_t getMinor(); 53 | uint16_t getManufacturerId(); 54 | NimBLEUUID getProximityUUID(); 55 | int8_t getSignalPower(); 56 | void setData(const uint8_t* data, uint8_t length); 57 | void setData(const BeaconData& data); 58 | void setMajor(uint16_t major); 59 | void setMinor(uint16_t minor); 60 | void setManufacturerId(uint16_t manufacturerId); 61 | void setProximityUUID(const NimBLEUUID& uuid); 62 | void setSignalPower(int8_t signalPower); 63 | 64 | private: 65 | BeaconData m_beaconData; 66 | }; // NimBLEBeacon 67 | 68 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL 69 | #endif // NIMBLE_CPP_BEACON_H_ 70 | -------------------------------------------------------------------------------- /src/NimBLEEddystoneTLM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_EDDYSTONETLM_H_ 19 | #define NIMBLE_CPP_EDDYSTONETLM_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER 23 | 24 | class NimBLEUUID; 25 | 26 | # include 27 | 28 | # define EDDYSTONE_TLM_FRAME_TYPE 0x20 29 | 30 | /** 31 | * @brief Representation of a beacon. 32 | * See: 33 | * * https://github.com/google/eddystone 34 | */ 35 | class NimBLEEddystoneTLM { 36 | public: 37 | struct BeaconData { 38 | uint8_t frameType{EDDYSTONE_TLM_FRAME_TYPE}; 39 | uint8_t version{0}; 40 | uint16_t volt{3300}; 41 | uint16_t temp{23 * 256}; 42 | uint32_t advCount{0}; 43 | uint32_t tmil{0}; 44 | } __attribute__((packed)); 45 | 46 | const BeaconData getData(); 47 | NimBLEUUID getUUID(); 48 | uint8_t getVersion(); 49 | uint16_t getVolt(); 50 | int16_t getTemp(); 51 | uint32_t getCount(); 52 | uint32_t getTime(); 53 | std::string toString(); 54 | void setData(const uint8_t* data, uint8_t length); 55 | void setData(const BeaconData& data); 56 | void setUUID(const NimBLEUUID& l_uuid); 57 | void setVersion(uint8_t version); 58 | void setVolt(uint16_t volt); 59 | void setTemp(int16_t temp); 60 | void setCount(uint32_t advCount); 61 | void setTime(uint32_t tmil); 62 | 63 | private: 64 | uint16_t beaconUUID{0xFEAA}; 65 | BeaconData m_eddystoneData; 66 | 67 | }; // NimBLEEddystoneTLM 68 | 69 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER 70 | #endif // NIMBLE_CPP_EDDYSTONETLM_H_ 71 | -------------------------------------------------------------------------------- /src/NimBLEL2CAPServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // (C) Dr. Michael 'Mickey' Lauer 3 | // 4 | 5 | #include "NimBLEL2CAPServer.h" 6 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM 7 | 8 | # include "NimBLEL2CAPChannel.h" 9 | # include "NimBLEDevice.h" 10 | # include "NimBLELog.h" 11 | 12 | static const char* LOG_TAG = "NimBLEL2CAPServer"; 13 | 14 | NimBLEL2CAPServer::NimBLEL2CAPServer() { 15 | // Nothing to do here... 16 | } 17 | 18 | NimBLEL2CAPServer::~NimBLEL2CAPServer() { 19 | // Delete all services 20 | for (auto service : this->services) { 21 | delete service; 22 | } 23 | } 24 | 25 | NimBLEL2CAPChannel* NimBLEL2CAPServer::createService(const uint16_t psm, 26 | const uint16_t mtu, 27 | NimBLEL2CAPChannelCallbacks* callbacks) { 28 | auto service = new NimBLEL2CAPChannel(psm, mtu, callbacks); 29 | auto rc = ble_l2cap_create_server(psm, mtu, NimBLEL2CAPChannel::handleL2capEvent, service); 30 | 31 | if (rc != 0) { 32 | NIMBLE_LOGE(LOG_TAG, "Could not ble_l2cap_create_server: %d", rc); 33 | return nullptr; 34 | } 35 | 36 | this->services.push_back(service); 37 | return service; 38 | } 39 | 40 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM 41 | -------------------------------------------------------------------------------- /src/NimBLEL2CAPServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // (C) Dr. Michael 'Mickey' Lauer 3 | // 4 | 5 | #ifndef NIMBLE_CPP_L2CAPSERVER_H_ 6 | #define NIMBLE_CPP_L2CAPSERVER_H_ 7 | #include "nimconfig.h" 8 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM 9 | 10 | # include "inttypes.h" 11 | # include 12 | 13 | class NimBLEL2CAPChannel; 14 | class NimBLEL2CAPChannelCallbacks; 15 | 16 | /** 17 | * @brief L2CAP server class. 18 | * 19 | * Encapsulates a L2CAP server that can hold multiple services. Every service is represented by a channel object 20 | * and an assorted set of callbacks. 21 | */ 22 | class NimBLEL2CAPServer { 23 | public: 24 | /// @brief Register a new L2CAP service instance. 25 | /// @param psm The port multiplexor service number. 26 | /// @param mtu The maximum transmission unit. 27 | /// @param callbacks The callbacks for this service. 28 | /// @return the newly created object, if the server registration was successful. 29 | NimBLEL2CAPChannel* createService(const uint16_t psm, const uint16_t mtu, NimBLEL2CAPChannelCallbacks* callbacks); 30 | 31 | private: 32 | NimBLEL2CAPServer(); 33 | ~NimBLEL2CAPServer(); 34 | std::vector services; 35 | 36 | friend class NimBLEL2CAPChannel; 37 | friend class NimBLEDevice; 38 | }; 39 | 40 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM 41 | #endif // NIMBLE_CPP_L2CAPSERVER_H_ 42 | -------------------------------------------------------------------------------- /src/NimBLELocalAttribute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_LOCAL_ATTRIBUTE_H_ 19 | #define NIMBLE_CPP_LOCAL_ATTRIBUTE_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL 23 | 24 | # include "NimBLEAttribute.h" 25 | 26 | /** 27 | * @brief A base class for local BLE attributes. 28 | */ 29 | class NimBLELocalAttribute : public NimBLEAttribute { 30 | public: 31 | /** 32 | * @brief Get the removed flag. 33 | * @return The removed flag. 34 | */ 35 | uint8_t getRemoved() const { return m_removed; } 36 | 37 | protected: 38 | /** 39 | * @brief Construct a local attribute. 40 | */ 41 | NimBLELocalAttribute(const NimBLEUUID& uuid, uint16_t handle) : NimBLEAttribute{uuid, handle}, m_removed{0} {} 42 | 43 | /** 44 | * @brief Destroy the local attribute. 45 | */ 46 | ~NimBLELocalAttribute() = default; 47 | 48 | /** 49 | * @brief Set the removed flag. 50 | * @param [in] removed The removed flag. 51 | */ 52 | void setRemoved(uint8_t removed) { m_removed = removed; } 53 | 54 | uint8_t m_removed{0}; 55 | }; 56 | 57 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL 58 | #endif // NIMBLE_CPP_LOCAL_ATTRIBUTE_H_ 59 | -------------------------------------------------------------------------------- /src/NimBLERemoteDescriptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "NimBLERemoteDescriptor.h" 19 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL 20 | 21 | # include "NimBLERemoteCharacteristic.h" 22 | 23 | /** 24 | * @brief Remote descriptor constructor. 25 | * @param [in] pRemoteCharacteristic A pointer to the Characteristic that this belongs to. 26 | * @param [in] dsc A pointer to the struct that contains the descriptor information. 27 | */ 28 | NimBLERemoteDescriptor::NimBLERemoteDescriptor(const NimBLERemoteCharacteristic* pRemoteCharacteristic, 29 | const ble_gatt_dsc* dsc) 30 | : NimBLERemoteValueAttribute{dsc->uuid, dsc->handle}, 31 | m_pRemoteCharacteristic{pRemoteCharacteristic} {} // NimBLERemoteDescriptor 32 | 33 | /** 34 | * @brief Get the characteristic that owns this descriptor. 35 | * @return The characteristic that owns this descriptor. 36 | */ 37 | NimBLERemoteCharacteristic* NimBLERemoteDescriptor::getRemoteCharacteristic() const { 38 | return const_cast(m_pRemoteCharacteristic); 39 | } // getRemoteCharacteristic 40 | 41 | /** 42 | * @brief Return a string representation of this Remote Descriptor. 43 | * @return A string representation of this Remote Descriptor. 44 | */ 45 | std::string NimBLERemoteDescriptor::toString() const { 46 | std::string res = "Descriptor: uuid: " + getUUID().toString(); 47 | char val[6]; 48 | res += ", handle: "; 49 | snprintf(val, sizeof(val), "%d", getHandle()); 50 | res += val; 51 | 52 | return res; 53 | } // toString 54 | 55 | NimBLEClient* NimBLERemoteDescriptor::getClient() const { 56 | return m_pRemoteCharacteristic->getClient(); 57 | } 58 | 59 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL 60 | -------------------------------------------------------------------------------- /src/NimBLERemoteDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_REMOTE_DESCRIPTOR_H_ 19 | #define NIMBLE_CPP_REMOTE_DESCRIPTOR_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL 23 | 24 | # include "NimBLERemoteValueAttribute.h" 25 | 26 | class NimBLERemoteCharacteristic; 27 | class NimBLEClient; 28 | 29 | /** 30 | * @brief A model of remote BLE descriptor. 31 | */ 32 | class NimBLERemoteDescriptor : public NimBLERemoteValueAttribute { 33 | public: 34 | NimBLERemoteCharacteristic* getRemoteCharacteristic() const; 35 | std::string toString(void) const; 36 | NimBLEClient* getClient() const override; 37 | 38 | private: 39 | friend class NimBLERemoteCharacteristic; 40 | 41 | NimBLERemoteDescriptor(const NimBLERemoteCharacteristic* pRemoteCharacteristic, const ble_gatt_dsc* dsc); 42 | ~NimBLERemoteDescriptor() = default; 43 | 44 | const NimBLERemoteCharacteristic* m_pRemoteCharacteristic; 45 | }; 46 | 47 | #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL 48 | #endif // NIMBLE_CPP_REMOTE_DESCRIPTOR_H_ 49 | -------------------------------------------------------------------------------- /src/NimBLEUUID.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_UUID_H_ 19 | #define NIMBLE_CPP_UUID_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED 23 | 24 | # if defined(CONFIG_NIMBLE_CPP_IDF) 25 | # include "host/ble_uuid.h" 26 | # else 27 | # include "nimble/nimble/host/include/host/ble_uuid.h" 28 | # endif 29 | 30 | /**** FIX COMPILATION ****/ 31 | # undef min 32 | # undef max 33 | /**************************/ 34 | 35 | # include 36 | # include 37 | 38 | /** 39 | * @brief A model of a %BLE UUID. 40 | */ 41 | class NimBLEUUID { 42 | public: 43 | /** 44 | * @brief Created a blank UUID. 45 | */ 46 | NimBLEUUID() = default; 47 | NimBLEUUID(const ble_uuid_any_t& uuid); 48 | NimBLEUUID(const std::string& uuid); 49 | NimBLEUUID(uint16_t uuid); 50 | NimBLEUUID(uint32_t uuid); 51 | NimBLEUUID(const ble_uuid128_t* uuid); 52 | NimBLEUUID(const uint8_t* pData, size_t size); 53 | NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth); 54 | 55 | uint8_t bitSize() const; 56 | const uint8_t* getValue() const; 57 | const ble_uuid_t* getBase() const; 58 | bool equals(const NimBLEUUID& uuid) const; 59 | std::string toString() const; 60 | static NimBLEUUID fromString(const std::string& uuid); 61 | const NimBLEUUID& to128(); 62 | const NimBLEUUID& to16(); 63 | const NimBLEUUID& reverseByteOrder(); 64 | 65 | bool operator==(const NimBLEUUID& rhs) const; 66 | bool operator!=(const NimBLEUUID& rhs) const; 67 | operator std::string() const; 68 | 69 | private: 70 | ble_uuid_any_t m_uuid{}; 71 | }; // NimBLEUUID 72 | 73 | #endif // CONFIG_BT_ENABLED 74 | #endif // NIMBLE_CPP_UUID_H_ 75 | -------------------------------------------------------------------------------- /src/NimBLEUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2025 Ryan Powell and 3 | * esp-nimble-cpp, NimBLE-Arduino contributors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef NIMBLE_CPP_UTILS_H_ 19 | #define NIMBLE_CPP_UTILS_H_ 20 | 21 | #include "nimconfig.h" 22 | #if CONFIG_BT_ENABLED 23 | 24 | # include 25 | 26 | class NimBLEAddress; 27 | 28 | /** 29 | * @brief A structure to hold data for a task that is waiting for a response. 30 | * @details This structure is used in conjunction with NimBLEUtils::taskWait() and NimBLEUtils::taskRelease(). 31 | * All items are optional, the m_pHandle will be set in taskWait(). 32 | */ 33 | struct NimBLETaskData { 34 | NimBLETaskData(void* pInstance = nullptr, int flags = 0, void* buf = nullptr); 35 | ~NimBLETaskData(); 36 | void* m_pInstance{nullptr}; 37 | mutable int m_flags{0}; 38 | void* m_pBuf{nullptr}; 39 | 40 | private: 41 | mutable void* m_pHandle{nullptr}; // semaphore or task handle 42 | friend class NimBLEUtils; 43 | }; 44 | 45 | /** 46 | * @brief A BLE Utility class with methods for debugging and general purpose use. 47 | */ 48 | class NimBLEUtils { 49 | public: 50 | static const char* gapEventToString(uint8_t eventType); 51 | static std::string dataToHexString(const uint8_t* source, uint8_t length); 52 | static const char* advTypeToString(uint8_t advType); 53 | static const char* returnCodeToString(int rc); 54 | static NimBLEAddress generateAddr(bool nrpa); 55 | static bool taskWait(const NimBLETaskData& taskData, uint32_t timeout); 56 | static void taskRelease(const NimBLETaskData& taskData, int rc = 0); 57 | }; 58 | 59 | #endif // CONFIG_BT_ENABLED 60 | #endif // NIMBLE_CPP_UTILS_H_ 61 | -------------------------------------------------------------------------------- /src/nimble/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Mynewt NimBLE 2 | Copyright 2015-2022 The Apache Software Foundation 3 | Modifications Copyright 2017-2022 Espressif Systems (Shanghai) CO., LTD. 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | Portions of this software were developed at 9 | Runtime Inc, copyright 2015. 10 | -------------------------------------------------------------------------------- /src/nimble/RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | # RELEASE NOTES 2 | 3 | 09 August 2023 - Apache NimBLE v1.6.0 4 | 5 | For full release notes, please visit the 6 | [Apache Mynewt Wiki](https://cwiki.apache.org/confluence/display/MYNEWT/Release+Notes). 7 | 8 | Apache NimBLE is an open-source Bluetooth 5.4 stack (both Host & Controller) that completely 9 | replaces the proprietary SoftDevice on Nordic chipsets. 10 | 11 | New features in this version of NimBLE include: 12 | 13 | * Initial support for ISO broacaster 14 | * Support for Bluetooth Core Specification 5.4 15 | * FEM antenna control 16 | * nRF PHY driver unification 17 | * IPC HCI transport improvements 18 | 19 | If working on next-generation RTOS and Bluetooth protocol stack 20 | sounds exciting to you, get in touch, by sending a mail to the Apache Mynewt 21 | Developer's list, dev@mynewt.apache.org. 22 | -------------------------------------------------------------------------------- /src/nimble/console/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONSOLE_H__ 2 | #define __CONSOLE_H__ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define console_printf(_fmt, ...) printf(_fmt, ##__VA_ARGS__) 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif /* __CONSOLE_H__ */ -------------------------------------------------------------------------------- /src/nimble/esp_port/esp-hci/include/esp_nimble_hci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef __ESP_NIMBLE_HCI_H__ 8 | #define __ESP_NIMBLE_HCI_H__ 9 | 10 | #include "nimble/nimble/transport/include/nimble/transport.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #define BLE_HCI_UART_H4_NONE 0x00 17 | #define BLE_HCI_UART_H4_CMD 0x01 18 | #define BLE_HCI_UART_H4_ACL 0x02 19 | #define BLE_HCI_UART_H4_SCO 0x03 20 | #define BLE_HCI_UART_H4_EVT 0x04 21 | 22 | /** 23 | * @brief Initialize VHCI transport layer between NimBLE Host and 24 | * ESP Bluetooth controller 25 | * 26 | * This function initializes the transport buffers to be exchanged 27 | * between NimBLE host and ESP controller. It also registers required 28 | * host callbacks with the controller. 29 | * 30 | * @return 31 | * - ESP_OK if the initialization is successful 32 | * - Appropriate error code from esp_err_t in case of an error 33 | */ 34 | esp_err_t esp_nimble_hci_init(void); 35 | 36 | /** 37 | * @brief Deinitialize VHCI transport layer between NimBLE Host and 38 | * ESP Bluetooth controller 39 | * 40 | * @note This function should be called after the NimBLE host is deinitialized. 41 | * 42 | * @return 43 | * - ESP_OK if the deinitialization is successful 44 | * - Appropriate error codes from esp_err_t in case of an error 45 | */ 46 | esp_err_t esp_nimble_hci_deinit(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __ESP_NIMBLE_HCI_H__ */ 53 | -------------------------------------------------------------------------------- /src/nimble/esp_port/port/include/bt_osi_mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "sdkconfig.h" 10 | #include "esp_attr.h" 11 | #include "esp_heap_caps.h" 12 | 13 | void *bt_osi_mem_malloc(size_t size); 14 | 15 | void *bt_osi_mem_calloc(size_t n, size_t size); 16 | 17 | void *bt_osi_mem_malloc_internal(size_t size); 18 | 19 | void *bt_osi_mem_calloc_internal(size_t n, size_t size); 20 | 21 | void bt_osi_mem_free(void *ptr); 22 | -------------------------------------------------------------------------------- /src/nimble/esp_port/port/include/esp_nimble_mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef __ESP_NIMBLE_MEM_H__ 8 | #define __ESP_NIMBLE_MEM_H__ 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #if 0 //ESP_IDF_VERSION_MAJOR >= 5 17 | // #pragma message "This file should be replaced with bt_osi_mem.h, used here for compatibility" 18 | 19 | #include "bt_osi_mem.h" 20 | #define nimble_platform_mem_malloc bt_osi_mem_malloc 21 | #define nimble_platform_mem_calloc bt_osi_mem_calloc 22 | #define nimble_platform_mem_free bt_osi_mem_free 23 | 24 | #else 25 | 26 | void *nimble_platform_mem_malloc(size_t size); 27 | void *nimble_platform_mem_calloc(size_t n, size_t size); 28 | void nimble_platform_mem_free(void *ptr); 29 | 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* __ESP_NIMBLE_MEM_H__ */ 37 | -------------------------------------------------------------------------------- /src/nimble/esp_port/port/src/exp_nimble_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifdef ESP_PLATFORM 8 | 9 | #include "esp_attr.h" 10 | #include "esp_heap_caps.h" 11 | #include "nimconfig.h" 12 | #include "../include/esp_nimble_mem.h" 13 | 14 | void *nimble_platform_mem_malloc(size_t size) 15 | { 16 | #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL 17 | return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); 18 | #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL 19 | return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); 20 | #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT 21 | return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); 22 | #else 23 | return malloc(size); 24 | #endif 25 | } 26 | 27 | void *nimble_platform_mem_calloc(size_t n, size_t size) 28 | { 29 | #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL 30 | return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); 31 | #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL 32 | return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); 33 | #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT 34 | return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); 35 | #else 36 | return calloc(n, size); 37 | #endif 38 | } 39 | 40 | void nimble_platform_mem_free(void *ptr) 41 | { 42 | heap_caps_free(ptr); 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /src/nimble/esp_port/port/transport/include/esp_hci_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #ifndef H_ESP_HCI_DRIVER_ 7 | #define H_ESP_HCI_DRIVER_ 8 | #include 9 | 10 | /** 11 | * @brief Enumeration of HCI transport direction. 12 | */ 13 | typedef enum { 14 | HCI_DRIVER_DIR_C2H = 0x00, ///< From controller to host. 15 | HCI_DRIVER_DIR_H2C, ///< From host to controller. 16 | } hci_driver_direction_t; 17 | 18 | typedef enum { 19 | HCI_DRIVER_TYPE_CMD = 0x01, ///< HCI Command Indicator. 20 | HCI_DRIVER_TYPE_ACL, ///< HCI ACL Data Indicator. 21 | HCI_DRIVER_TYPE_SYNC, ///< HCI Synchronous Data Indicator. 22 | HCI_DRIVER_TYPE_EVT, ///< HCI Event Indicator. 23 | HCI_DRIVER_TYPE_ISO, ///< HCI Isochronous Data Indicator. 24 | HCI_DRIVER_TYPE_VENDOR, ///< HCI Vendor data Indicator. 25 | } hci_driver_data_type_t; 26 | 27 | typedef int hci_driver_forward_fn(hci_driver_data_type_t data_type, uint8_t *data, uint32_t length, 28 | hci_driver_direction_t dir); 29 | 30 | /** 31 | * @brief Structure of HCI driver operations. 32 | */ 33 | typedef struct hci_driver_ops { 34 | int (*hci_driver_tx)(hci_driver_data_type_t data_type, uint8_t *data, uint32_t length, 35 | hci_driver_direction_t dir); 36 | int (*hci_driver_init)(hci_driver_forward_fn *cb); 37 | void (*hci_driver_deinit)(void); 38 | } hci_driver_ops_t; 39 | 40 | 41 | #if CONFIG_BT_LE_HCI_INTERFACE_USE_RAM 42 | extern hci_driver_ops_t na_hci_driver_vhci_ops; 43 | #endif // CONFIG_BT_LE_HCI_INTERFACE_USE_RAM 44 | 45 | #if CONFIG_BT_LE_HCI_INTERFACE_USE_UART 46 | extern hci_driver_ops_t hci_driver_uart_ops; 47 | #if CONFIG_BT_LE_UART_HCI_DMA_MODE 48 | extern hci_driver_ops_t hci_driver_uart_dma_ops; 49 | #endif // CONFIG_BT_LE_UART_HCI_DMA_MODE 50 | #endif // CONFIG_BT_LE_HCI_INTERFACE_USE_UART 51 | 52 | #endif // H_ESP_HCI_DRIVER_ 53 | -------------------------------------------------------------------------------- /src/nimble/ext/tinycrypt/AUTHORS: -------------------------------------------------------------------------------- 1 | Architect: 2 | Rafael Misoczki 3 | 4 | Open Source Maintainer: 5 | Constanza Heath 6 | Rafael Misoczki 7 | 8 | Contributors: 9 | Constanza Heath 10 | Rafael Misoczki 11 | Flavio Santes 12 | Jarkko Sakkinen 13 | Chris Morrison 14 | Marti Bolivar 15 | Colin Ian King 16 | -------------------------------------------------------------------------------- /src/nimble/ext/tinycrypt/VERSION: -------------------------------------------------------------------------------- 1 | 0.2.8 2 | -------------------------------------------------------------------------------- /src/nimble/ext/tinycrypt/include/tinycrypt/constants.h: -------------------------------------------------------------------------------- 1 | /* constants.h - TinyCrypt interface to constants */ 2 | 3 | /* 4 | * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * - Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * - Neither the name of Intel Corporation nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | * @file 35 | * @brief -- Interface to constants. 36 | * 37 | */ 38 | 39 | #ifndef __TC_CONSTANTS_H__ 40 | #define __TC_CONSTANTS_H__ 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #include 47 | 48 | #ifndef NULL 49 | #define NULL ((void *)0) 50 | #endif 51 | 52 | #define TC_CRYPTO_SUCCESS 1 53 | #define TC_CRYPTO_FAIL 0 54 | 55 | #define TC_ZERO_BYTE 0x00 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* __TC_CONSTANTS_H__ */ 62 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_fem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_FEM_ 21 | #define H_BLE_FEM_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 28 | 29 | #if MYNEWT_VAL(BLE_FEM_PA) 30 | void ble_fem_pa_init(void); 31 | void ble_fem_pa_enable(void); 32 | void ble_fem_pa_disable(void); 33 | #if MYNEWT_VAL(BLE_FEM_PA_GAIN_TUNABLE) 34 | /* Configures FEM to selected TX power and returns expected PHY TX power */ 35 | int ble_fem_pa_tx_power_set(int tx_power); 36 | 37 | /* returns rounded FEM TX power */ 38 | int ble_fem_pa_tx_power_round(int tx_power); 39 | #endif 40 | #endif 41 | 42 | #if MYNEWT_VAL(BLE_FEM_LNA) 43 | void ble_fem_lna_init(void); 44 | void ble_fem_lna_enable(void); 45 | void ble_fem_lna_disable(void); 46 | 47 | #if MYNEWT_VAL(BLE_FEM_LNA_GAIN_TUNABLE) 48 | /* Return current value of FEM LNA RX gain (in dBm) */ 49 | int ble_fem_lna_rx_gain(void); 50 | #endif 51 | 52 | #endif 53 | 54 | #if MYNEWT_VAL(BLE_FEM_ANTENNA) 55 | /* 0 sets default antenna, any other value is FEM specific */ 56 | int ble_fem_antenna(uint8_t antenna); 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* H_BLE_FEM_ */ 64 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_crypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_CRYPTO_ 21 | #define H_BLE_LL_CRYPTO_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int 28 | ble_ll_crypto_cmac(const uint8_t *key, const uint8_t *in, int len, 29 | uint8_t *out); 30 | 31 | static inline int 32 | ble_ll_crypto_h6(const uint8_t *w, const uint8_t *key_id, uint8_t *out) 33 | { 34 | return ble_ll_crypto_cmac(w, key_id, 4, out); 35 | } 36 | 37 | static inline int 38 | ble_ll_crypto_h7(const uint8_t *salt, const uint8_t *w, uint8_t *out) 39 | { 40 | return ble_ll_crypto_cmac(salt, w, 16, out); 41 | } 42 | 43 | int ble_ll_crypto_h8(const uint8_t *k, const uint8_t *s, const uint8_t *key_id, 44 | uint8_t *out); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* H_BLE_LL_CRYPTO_ */ 51 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_EXT_ 21 | #define H_BLE_LL_EXT_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #if MYNEWT_VAL(BLE_LL_EXT) 28 | 29 | /* Quickstart guide: 30 | * - create scheduling item with sched_type set to BLE_LL_SCHED_EXTERNAL 31 | * - use sched_ext_type to differentiate between different types of custom items 32 | * - insert into scheduler using ble_ll_sched_insert() 33 | * - set LL state to BLE_LL_STATE_EXTERNAL when item is being executed 34 | * - set LL state back to BLE_LL_STATE_IDLE when item is done 35 | */ 36 | 37 | struct ble_ll_sched_item; 38 | 39 | /* Called when LL package is initialized (before ll_task is started) */ 40 | void ble_ll_ext_init(void); 41 | /* Called when LL is reset (i.e. HCI_Reset) */ 42 | void ble_ll_ext_reset(void); 43 | /* Called when LL is in "external" state and PHY starts to receive a PDU */ 44 | int ble_ll_ext_rx_isr_start(uint8_t pdu_type, struct ble_mbuf_hdr *rxhdr); 45 | /* Called when LL is in "external" state and PHY finished to receive a PDU */ 46 | int ble_ll_ext_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr); 47 | /* Called when PDU received in "external" state reaches LL */ 48 | void ble_ll_ext_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *rxhdr); 49 | /* Called when LL is in "external" state and was preempted */ 50 | void ble_ll_ext_halt(void); 51 | /* Called when LL is in "external" state and PHY failed to receive a PDU */ 52 | void ble_ll_ext_wfr_timer_exp(void); 53 | /* Called when an "external" scheduling item was removed from scheduler queue */ 54 | void ble_ll_ext_sched_removed(struct ble_ll_sched_item *sch); 55 | 56 | #endif 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* H_BLE_LL_EXT_ */ 63 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_iso.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_ISO 21 | #define H_BLE_LL_ISO 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int ble_ll_iso_read_tx_sync(const uint8_t *cmdbuf, uint8_t len); 30 | int ble_ll_iso_set_cig_param(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf, uint8_t *rsplen); 31 | int ble_ll_iso_set_cig_param_test(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf, uint8_t *rsplen); 32 | int ble_ll_iso_create_cis(const uint8_t *cmdbuf, uint8_t len); 33 | int ble_ll_iso_disconnect_cmd(const struct ble_hci_lc_disconnect_cp *cmd); 34 | int ble_ll_iso_remove_cig(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf, uint8_t *rsplen); 35 | int ble_ll_iso_accept_cis_req(const uint8_t *cmdbuf, uint8_t len); 36 | int ble_ll_iso_reject_cis_req(const uint8_t *cmdbuf, uint8_t len); 37 | int ble_ll_iso_create_big(const uint8_t *cmdbuf, uint8_t len); 38 | int ble_ll_iso_create_big_test(const uint8_t *cmdbuf, uint8_t len); 39 | int ble_ll_iso_terminate_big(const uint8_t *cmdbuf, uint8_t len); 40 | int ble_ll_iso_big_create_sync(const uint8_t *cmdbuf, uint8_t len); 41 | int ble_ll_iso_big_terminate_sync(const uint8_t *cmdbuf, uint8_t len); 42 | int ble_ll_iso_setup_iso_data_path(const uint8_t *cmdbuf, uint8_t len); 43 | int ble_ll_iso_remove_iso_data_path(const uint8_t *cmdbuf, uint8_t len); 44 | int ble_ll_iso_transmit_test(const uint8_t *cmdbuf, uint8_t len); 45 | int ble_ll_iso_receive_test(const uint8_t *cmdbuf, uint8_t len); 46 | int ble_ll_iso_read_counters_test(const uint8_t *cmdbuf, uint8_t len); 47 | int ble_ll_iso_end_test(const uint8_t *cmdbuf, uint8_t len); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_iso_big.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_ISO_BIG_ 21 | #define H_BLE_LL_ISO_BIG_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #if MYNEWT_VAL(BLE_LL_ISO_BROADCASTER) 28 | 29 | struct ble_ll_iso_big; 30 | struct ble_ll_iso_bis; 31 | 32 | int ble_ll_iso_big_biginfo_copy(struct ble_ll_iso_big *big, uint8_t *dptr, 33 | uint32_t base_ticks, uint8_t base_rem_us); 34 | int ble_ll_iso_big_biginfo_len(struct ble_ll_iso_big *big); 35 | 36 | struct ble_ll_iso_bis *ble_ll_iso_big_find_bis_by_handle(uint16_t conn_handle); 37 | struct ble_ll_isoal_mux *ble_ll_iso_big_find_mux_by_handle(uint16_t conn_handle); 38 | int ble_ll_iso_big_last_tx_timestamp_get(struct ble_ll_iso_bis *bis, 39 | uint16_t *packet_seq_num, 40 | uint32_t *timestamp); 41 | 42 | void ble_ll_iso_big_chan_map_update(void); 43 | 44 | void ble_ll_iso_big_halt(void); 45 | 46 | int ble_ll_iso_big_hci_create(const uint8_t *cmdbuf, uint8_t len); 47 | int ble_ll_iso_big_hci_create_test(const uint8_t *cmdbuf, uint8_t len); 48 | int ble_ll_iso_big_hci_terminate(const uint8_t *cmdbuf, uint8_t len); 49 | void ble_ll_iso_big_hci_evt_complete(void); 50 | 51 | void ble_ll_iso_big_init(void); 52 | void ble_ll_iso_big_reset(void); 53 | 54 | #endif /* BLE_LL_ISO_BROADCASTER */ 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* H_BLE_LL_ISO_BIG_ */ 61 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_pdu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_PDU_ 21 | #define H_BLE_LL_PDU_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Header mask for keystream generation */ 30 | #define BLE_LL_PDU_HEADERMASK_DATA (0xe3) 31 | #define BLE_LL_PDU_HEADERMASK_BIS (0xc3) 32 | #define BLE_LL_PDU_HEADERMASK_CIS (0xa3) 33 | 34 | #define BLE_LL_PDU_PREAMBLE_1M_LEN (1) 35 | #define BLE_LL_PDU_PREAMBLE_2M_LEN (2) 36 | #define BLE_LL_PDU_AA_LEN (4) 37 | #define BLE_LL_PDU_HEADER_LEN (2) 38 | #define BLE_LL_PDU_CRC_LEN (3) 39 | 40 | uint32_t ble_ll_pdu_syncword_us(uint8_t phy_mode); 41 | uint32_t ble_ll_pdu_us(uint8_t payload_len, uint8_t phy_mode); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* H_BLE_LL_PDU_ */ 48 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_rfmgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_RFMGMT_ 21 | #define H_BLE_LL_RFMGMT_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include "nimble/nimble/controller/include/controller/ble_ll_tmr.h" 28 | 29 | void ble_ll_rfmgmt_init(void); 30 | 31 | #if MYNEWT_VAL(BLE_LL_RFMGMT_ENABLE_TIME) > 0 32 | 33 | void ble_ll_rfmgmt_reset(void); 34 | 35 | /* Notify rfmgmt that scan window has changed (only called from ble_ll_scan) */ 36 | void ble_ll_rfmgmt_scan_changed(bool enabled, uint32_t next_window); 37 | 38 | /* Notify rfmgmt that 1st scheduled item has changed (only called from ble_ll_sched) */ 39 | void ble_ll_rfmgmt_sched_changed(struct ble_ll_sched_item *first); 40 | 41 | /* Notify rfmgmt that RF is no longer needed by current event */ 42 | void ble_ll_rfmgmt_release(void); 43 | 44 | /* Enables RF immediately and returns tick at which RF will be fully enabled */ 45 | uint32_t ble_ll_rfmgmt_enable_now(void); 46 | 47 | /* Returns true only if RF is currently fully enabled (i.e. not off or enabling) */ 48 | bool ble_ll_rfmgmt_is_enabled(void); 49 | 50 | #else 51 | 52 | static inline void ble_ll_rfmgmt_reset(void) { } 53 | static inline void ble_ll_rfmgmt_scan_changed(bool e, uint32_t n) { } 54 | static inline void ble_ll_rfmgmt_sched_changed(struct ble_ll_sched_item *f) { } 55 | static inline void ble_ll_rfmgmt_release(void) { } 56 | static inline uint32_t ble_ll_rfmgmt_enable_now(void) { return ble_ll_tmr_get(); } 57 | static inline bool ble_ll_rfmgmt_is_enabled(void) { return true; } 58 | 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* H_BLE_LL_RFMGMT_ */ 66 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_scan_aux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_SCAN_AUX_ 21 | #define H_BLE_LL_SCAN_AUX_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) 28 | 29 | struct ble_ll_scan_aux_data; 30 | 31 | void ble_ll_scan_aux_init(void); 32 | int ble_ll_scan_aux_sched(struct ble_ll_scan_aux_data *aux, uint32_t pdu_ticks, 33 | uint8_t pdu_rem_us, uint32_t aux_ptr); 34 | int ble_ll_scan_aux_rx_isr_start(uint8_t pdu_type, struct ble_mbuf_hdr *rxhdr); 35 | int ble_ll_scan_aux_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok); 36 | void ble_ll_scan_aux_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *rxhdr); 37 | 38 | void ble_ll_scan_aux_break(struct ble_ll_scan_aux_data *aux); 39 | void ble_ll_scan_aux_wfr_timer_exp(void); 40 | void ble_ll_scan_aux_halt(void); 41 | void ble_ll_scan_aux_sched_remove(struct ble_ll_sched_item *sch); 42 | 43 | int ble_ll_scan_aux_rx_isr_end_on_ext(struct ble_ll_scan_sm *scansm, 44 | struct os_mbuf *rxpdu); 45 | void ble_ll_scan_aux_pkt_in_on_ext(struct os_mbuf *rxpdu, 46 | struct ble_mbuf_hdr *rxhdr); 47 | 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* H_BLE_LL_SCAN_AUX_ */ 55 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | 22 | #define INT16_GT(_a, _b) ((int16_t)((_a) - (_b)) > 0) 23 | #define INT16_LT(_a, _b) ((int16_t)((_a) - (_b)) < 0) 24 | #define INT16_LTE(_a, _b) ((int16_t)((_a) - (_b)) <= 0) 25 | 26 | #define MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b)) 27 | #define MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b)) 28 | #define CLAMP(_n, _min, _max) (MAX(_min, MIN(_n, _max))) 29 | #define IN_RANGE(_n, _min, _max) (((_n) >= (_min)) && ((_n) <= (_max))) 30 | 31 | int ble_ll_utils_verify_aa(uint32_t aa); 32 | uint32_t ble_ll_utils_calc_aa(void); 33 | uint32_t ble_ll_utils_calc_seed_aa(void); 34 | uint32_t ble_ll_utils_calc_big_aa(uint32_t seed_aa, uint32_t n); 35 | 36 | uint8_t ble_ll_utils_chan_map_remap(const uint8_t *chan_map, uint8_t remap_index); 37 | uint8_t ble_ll_utils_chan_map_used_get(const uint8_t *chan_map); 38 | 39 | uint8_t ble_ll_utils_dci_csa2(uint16_t counter, uint16_t chan_id, 40 | uint8_t num_used_chans, const uint8_t *chan_map); 41 | uint16_t ble_ll_utils_dci_iso_event(uint16_t counter, uint16_t chan_id, 42 | uint16_t *prn_sub_lu, uint8_t chan_map_used, 43 | const uint8_t *chan_map, uint16_t *remap_idx); 44 | uint16_t ble_ll_utils_dci_iso_subevent(uint16_t chan_id, uint16_t *prn_sub_lu, 45 | uint8_t chan_map_used, const uint8_t *chan_map, 46 | uint16_t *remap_idx); 47 | 48 | uint32_t ble_ll_utils_calc_window_widening(uint32_t anchor_point, 49 | uint32_t last_anchor_point, 50 | uint8_t central_sca); 51 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_ll_whitelist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_WHITELIST_ 21 | #define H_BLE_LL_WHITELIST_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Clear the whitelist */ 28 | int ble_ll_whitelist_clear(void); 29 | 30 | /* Read the size of the whitelist */ 31 | int ble_ll_whitelist_read_size(uint8_t *rspbuf, uint8_t *rsplen); 32 | 33 | /* Add a device to the whitelist */ 34 | int ble_ll_whitelist_add(const uint8_t *cmdbuf, uint8_t len); 35 | 36 | /* Remove a device fromthe whitelist */ 37 | int ble_ll_whitelist_rmv(const uint8_t *cmdbuf, uint8_t len); 38 | 39 | /* Enable whitelisting */ 40 | void ble_ll_whitelist_enable(void); 41 | 42 | /* Disable whitelisting */ 43 | void ble_ll_whitelist_disable(void); 44 | 45 | /* Boolean function returning true if address matches a whitelist entry */ 46 | int ble_ll_whitelist_match(uint8_t *addr, uint8_t addr_type, int is_ident); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* H_BLE_LL_WHITELIST_ */ 53 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/include/controller/ble_phy_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_PHY_TRACE_ 21 | #define H_BLE_PHY_TRACE_ 22 | 23 | #include "nimble/porting/nimble/include/os/os_trace_api.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define BLE_PHY_TRACE_ID_START_TX 0 30 | #define BLE_PHY_TRACE_ID_START_RX 1 31 | #define BLE_PHY_TRACE_ID_DISABLE 2 32 | 33 | #if MYNEWT_VAL(BLE_PHY_SYSVIEW) 34 | 35 | extern uint32_t ble_phy_trace_off; 36 | 37 | void ble_phy_trace_init(void); 38 | 39 | static inline void 40 | ble_phy_trace_void(unsigned id) 41 | { 42 | os_trace_api_void(ble_phy_trace_off + id); 43 | } 44 | 45 | static inline void 46 | ble_phy_trace_u32(unsigned id, uint32_t p1) 47 | { 48 | os_trace_api_u32(ble_phy_trace_off + id, p1); 49 | } 50 | 51 | static inline void 52 | ble_phy_trace_u32x2(unsigned id, uint32_t p1, uint32_t p2) 53 | { 54 | os_trace_api_u32x2(ble_phy_trace_off + id, p1, p2); 55 | } 56 | 57 | static inline void 58 | ble_phy_trace_u32x3(unsigned id, uint32_t p1, uint32_t p2, uint32_t p3) 59 | { 60 | os_trace_api_u32x3(ble_phy_trace_off + id, p1, p2, p3); 61 | } 62 | 63 | #else 64 | 65 | static inline void 66 | ble_phy_trace_init(void) 67 | { 68 | } 69 | 70 | static inline void 71 | ble_phy_trace_void(unsigned id) 72 | { 73 | } 74 | 75 | static inline void 76 | ble_phy_trace_u32(unsigned id, uint32_t p1) 77 | { 78 | } 79 | 80 | static inline void 81 | ble_phy_trace_u32x2(unsigned id, uint32_t p1, uint32_t p2) 82 | { 83 | } 84 | 85 | static inline void 86 | ble_phy_trace_u32x3(unsigned id, uint32_t p1, uint32_t p2, uint32_t p3) 87 | { 88 | } 89 | 90 | #endif 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* H_BLE_PHY_TRACE_ */ 97 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_crypto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | int 28 | ble_ll_crypto_cmac(const uint8_t *key, const uint8_t *in, int len, 29 | uint8_t *out) 30 | { 31 | struct tc_aes_key_sched_struct sched; 32 | struct tc_cmac_struct state; 33 | 34 | if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) { 35 | return -1; 36 | } 37 | 38 | if (tc_cmac_update(&state, in, len) == TC_CRYPTO_FAIL) { 39 | return -1; 40 | } 41 | 42 | if (tc_cmac_final(out, &state) == TC_CRYPTO_FAIL) { 43 | return -1; 44 | } 45 | 46 | return 0; 47 | } 48 | 49 | int 50 | ble_ll_crypto_h8(const uint8_t *k, const uint8_t *s, const uint8_t *key_id, 51 | uint8_t *out) 52 | { 53 | uint8_t ik[16]; 54 | int rc; 55 | 56 | rc = ble_ll_crypto_cmac(s, k, 16, ik); 57 | if (rc) { 58 | return rc; 59 | } 60 | 61 | return ble_ll_crypto_cmac(ik, key_id, 4, out); 62 | } 63 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_ctrl_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_CTRL_PRIV_ 21 | #define H_BLE_LL_CTRL_PRIV_ 22 | 23 | #include "nimble/nimble/controller/include/controller/ble_ll_conn.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void ble_ll_ctrl_init_conn_sm(struct ble_ll_conn_sm *connsm); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* H_BLE_LL_CTRL_PRIV_ */ 36 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_dtm_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_TEST_PRIV_ 21 | #define H_BLE_LL_TEST_PRIV_ 22 | 23 | #include 24 | #include 25 | #include "nimble/nimble/include/nimble/ble.h" 26 | 27 | int ble_ll_hci_dtm_tx_test(const uint8_t *cmdbuf, uint8_t len); 28 | int ble_ll_hci_dtm_tx_test_v2(const uint8_t *cmdbuf, uint8_t len); 29 | 30 | int ble_ll_hci_dtm_rx_test(const uint8_t *cmdbuf, uint8_t len); 31 | int ble_ll_hci_dtm_rx_test_v2(const uint8_t *cmdbuf, uint8_t len); 32 | 33 | int ble_ll_dtm_end_test(uint8_t *rsp, uint8_t *rsplen); 34 | 35 | int ble_ll_dtm_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa); 36 | int ble_ll_dtm_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr); 37 | void ble_ll_dtm_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr); 38 | void ble_ll_dtm_wfr_timer_exp(void); 39 | void ble_ll_dtm_reset(void); 40 | int ble_ll_dtm_enabled(void); 41 | #endif 42 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_hci_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_HCI_PRIV_ 21 | #define H_BLE_LL_HCI_PRIV_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #if MYNEWT_VAL(BLE_LL_HCI_VS) 28 | void ble_ll_hci_vs_init(void); 29 | int ble_ll_hci_vs_cmd_proc(const uint8_t *cmdbuf, uint8_t cmdlen, uint16_t ocf, 30 | uint8_t *rspbuf, uint8_t *rsplen); 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* H_BLE_LL_HCI_ */ 38 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_pdu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | static const uint16_t syncword_len[] = { 24 | [BLE_PHY_MODE_1M] = (BLE_LL_PDU_PREAMBLE_1M_LEN + BLE_LL_PDU_AA_LEN) * 8, 25 | [BLE_PHY_MODE_2M] = (BLE_LL_PDU_PREAMBLE_2M_LEN + BLE_LL_PDU_AA_LEN) * 4, 26 | [BLE_PHY_MODE_CODED_125KBPS] = 80 + 256 + 16 + 24, 27 | [BLE_PHY_MODE_CODED_500KBPS] = 80 + 256 + 16 + 24, 28 | }; 29 | 30 | static const uint16_t payload0_len[] = { 31 | [BLE_PHY_MODE_1M] = (BLE_LL_PDU_PREAMBLE_1M_LEN + BLE_LL_PDU_AA_LEN + 32 | BLE_LL_PDU_HEADER_LEN + BLE_LL_PDU_CRC_LEN) * 8, 33 | [BLE_PHY_MODE_2M] = (BLE_LL_PDU_PREAMBLE_2M_LEN + BLE_LL_PDU_AA_LEN + 34 | BLE_LL_PDU_HEADER_LEN + BLE_LL_PDU_CRC_LEN) * 4, 35 | [BLE_PHY_MODE_CODED_125KBPS] = 80 + 256 + 16 + 24 + 36 | 8 * (BLE_LL_PDU_HEADER_LEN * 8 + 24 + 3), 37 | [BLE_PHY_MODE_CODED_500KBPS] = 80 + 256 + 16 + 24 + 38 | 2 * (BLE_LL_PDU_HEADER_LEN * 8 + 24 + 3), 39 | }; 40 | 41 | static const uint8_t us_per_octet[] = { 42 | [BLE_PHY_MODE_1M] = 8, 43 | [BLE_PHY_MODE_2M] = 4, 44 | [BLE_PHY_MODE_CODED_125KBPS] = 64, 45 | [BLE_PHY_MODE_CODED_500KBPS] = 16, 46 | }; 47 | 48 | uint32_t 49 | ble_ll_pdu_syncword_us(uint8_t phy_mode) 50 | { 51 | return syncword_len[phy_mode]; 52 | } 53 | 54 | uint32_t 55 | ble_ll_pdu_us(uint8_t payload_len, uint8_t phy_mode) 56 | { 57 | return payload0_len[phy_mode] + (payload_len * us_per_octet[phy_mode]); 58 | } 59 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_LL_PRIV_ 21 | #define H_BLE_LL_PRIV_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | extern int8_t g_ble_ll_tx_power; 28 | extern int8_t g_ble_ll_tx_power_compensation; 29 | extern int8_t g_ble_ll_rx_power_compensation; 30 | 31 | int ble_ll_tx_power_round(int tx_power); 32 | void ble_ll_tx_power_set(int tx_power); 33 | 34 | static inline int 35 | ble_ll_rx_gain(void) 36 | { 37 | int gain = g_ble_ll_rx_power_compensation; 38 | 39 | #if MYNEWT_VAL(BLE_FEM_LNA) 40 | #if MYNEWT_VAL(BLE_FEM_LNA_GAIN_TUNABLE) 41 | gain += ble_fem_lna_rx_gain(); 42 | #else 43 | gain += MYNEWT_VAL(BLE_FEM_LNA_GAIN); 44 | #endif 45 | #endif 46 | 47 | return gain; 48 | } 49 | 50 | /* if there is any radio related activity enabled 51 | * (scanning, advertising, connection etc) 52 | */ 53 | #define BLE_LL_BUSY_EXCLUDE_CONNECTIONS 0x01 54 | 55 | int ble_ll_is_busy(unsigned int flags); 56 | 57 | #ifdef MYNEWT 58 | 59 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 60 | #include "nimble/porting/nimble/include/hal/hal_gpio.h" 61 | 62 | #define BLE_LL_DEBUG_GPIO_INIT(_name) \ 63 | if (MYNEWT_VAL(BLE_LL_DEBUG_GPIO_ ## _name) >= 0) { \ 64 | hal_gpio_init_out(MYNEWT_VAL(BLE_LL_DEBUG_GPIO_ ## _name), 0); \ 65 | } 66 | 67 | #define BLE_LL_DEBUG_GPIO(_name, _val) \ 68 | if (MYNEWT_VAL(BLE_LL_DEBUG_GPIO_ ## _name) >= 0) { \ 69 | hal_gpio_write(MYNEWT_VAL(BLE_LL_DEBUG_GPIO_ ## _name), !!(_val)); \ 70 | } 71 | 72 | #else 73 | #define BLE_LL_DEBUG_GPIO_INIT(_name) (void)(0) 74 | #define BLE_LL_DEBUG_GPIO(_name, _val) (void)(0) 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* H_BLE_LL_PRIV_ */ 82 | -------------------------------------------------------------------------------- /src/nimble/nimble/controller/src/ble_ll_trace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | #ifndef ESP_PLATFORM 20 | #include 21 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 22 | #include "nimble/porting/nimble/include/os/os_trace_api.h" 23 | #include "nimble/nimble/controller/include/controller/ble_ll_trace.h" 24 | 25 | #if MYNEWT_VAL(BLE_LL_SYSVIEW) 26 | 27 | static os_trace_module_t g_ble_ll_trace_mod; 28 | uint32_t ble_ll_trace_off; 29 | 30 | static void 31 | ble_ll_trace_module_send_desc(void) 32 | { 33 | os_trace_module_desc(&g_ble_ll_trace_mod, "0 ll_sched lls=%u cputime=%u start_time=%u"); 34 | os_trace_module_desc(&g_ble_ll_trace_mod, "1 ll_rx_start lls=%u pdu_type=%x"); 35 | os_trace_module_desc(&g_ble_ll_trace_mod, "2 ll_rx_end pdu_type=%x len=%u flags=%x"); 36 | os_trace_module_desc(&g_ble_ll_trace_mod, "3 ll_wfr_timer_exp lls=%u xcvr=%u rx_start=%u"); 37 | os_trace_module_desc(&g_ble_ll_trace_mod, "4 ll_ctrl_rx opcode=%u len=%u"); 38 | os_trace_module_desc(&g_ble_ll_trace_mod, "5 ll_conn_ev_start conn_handle=%u"); 39 | os_trace_module_desc(&g_ble_ll_trace_mod, "6 ll_conn_ev_end conn_handle=%u event_cntr=%u"); 40 | os_trace_module_desc(&g_ble_ll_trace_mod, "7 ll_conn_end conn_handle=%u event_cntr=%u err=%u"); 41 | os_trace_module_desc(&g_ble_ll_trace_mod, "8 ll_conn_tx len=%u offset=%u"); 42 | os_trace_module_desc(&g_ble_ll_trace_mod, "9 ll_conn_rx conn_sn=%u pdu_nesn=%u"); 43 | os_trace_module_desc(&g_ble_ll_trace_mod, "10 ll_adv_txdone inst=%u chanset=%x"); 44 | os_trace_module_desc(&g_ble_ll_trace_mod, "11 ll_adv_halt inst=%u"); 45 | os_trace_module_desc(&g_ble_ll_trace_mod, "12 ll_aux_ref aux=%p ref=%u"); 46 | os_trace_module_desc(&g_ble_ll_trace_mod, "13 ll_aux_unref aux=%p ref=%u"); 47 | } 48 | 49 | void 50 | ble_ll_trace_init(void) 51 | { 52 | ble_ll_trace_off = 53 | os_trace_module_register(&g_ble_ll_trace_mod, "ble_ll", 12, 54 | ble_ll_trace_module_send_desc); 55 | } 56 | #endif 57 | #endif 58 | -------------------------------------------------------------------------------- /src/nimble/nimble/drivers/nrf51/include/ble/xcvr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_XCVR_ 21 | #define H_BLE_XCVR_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Transceiver specific defintions */ 28 | /* NOTE: we have to account for the RTC output compare issue */ 29 | #define XCVR_PROC_DELAY_USECS (230) 30 | 31 | #define XCVR_RX_START_DELAY_USECS (140) 32 | #define XCVR_TX_START_DELAY_USECS (140) 33 | #define XCVR_TX_SCHED_DELAY_USECS \ 34 | (XCVR_TX_START_DELAY_USECS + XCVR_PROC_DELAY_USECS) 35 | #define XCVR_RX_SCHED_DELAY_USECS \ 36 | (XCVR_RX_START_DELAY_USECS + XCVR_PROC_DELAY_USECS) 37 | 38 | /* 39 | * Define HW whitelist size. This is the total possible whitelist size; 40 | * not necessarily the size that will be used (may be smaller) 41 | */ 42 | #define BLE_HW_WHITE_LIST_SIZE (8) 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* H_BLE_XCVR_ */ 49 | -------------------------------------------------------------------------------- /src/nimble/nimble/drivers/nrf5x/include/ble/xcvr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #if defined(ARDUINO_ARCH_NRF5) && (defined(NRF52_SERIES) || defined(NRF53_SERIES)) 21 | 22 | #ifndef H_BLE_XCVR_ 23 | #define H_BLE_XCVR_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #include 30 | 31 | #define XCVR_RX_RADIO_RAMPUP_USECS (40) 32 | #define XCVR_TX_RADIO_RAMPUP_USECS (40) 33 | 34 | /* We need to account for the RTC compare issue, we want it to be 5 ticks. 35 | * In case FEM turn on time is more than radio enable (i.e. 2 ticks) we want 36 | * to add 1 more tick to compensate for additional delay. 37 | * 38 | * TODO this file should be refactored... 39 | */ 40 | #if (MYNEWT_VAL(BLE_FEM_PA) && (MYNEWT_VAL(BLE_FEM_PA_TURN_ON_US) > 60)) || \ 41 | (MYNEWT_VAL(BLE_FEM_LNA) && (MYNEWT_VAL(BLE_FEM_LNA_TURN_ON_US) > 60)) 42 | #define XCVR_PROC_DELAY_USECS (183) 43 | #else 44 | #define XCVR_PROC_DELAY_USECS (153) 45 | #endif 46 | #define XCVR_RX_START_DELAY_USECS (XCVR_RX_RADIO_RAMPUP_USECS) 47 | #define XCVR_TX_START_DELAY_USECS (XCVR_TX_RADIO_RAMPUP_USECS) 48 | #define XCVR_TX_SCHED_DELAY_USECS \ 49 | (XCVR_TX_START_DELAY_USECS + XCVR_PROC_DELAY_USECS) 50 | #define XCVR_RX_SCHED_DELAY_USECS \ 51 | (XCVR_RX_START_DELAY_USECS + XCVR_PROC_DELAY_USECS) 52 | 53 | /* 54 | * Define HW whitelist size. This is the total possible whitelist size; 55 | * not necessarily the size that will be used (may be smaller) 56 | */ 57 | #define BLE_HW_WHITE_LIST_SIZE (8) 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* H_BLE_XCVR_ */ 64 | #endif /* defined(ARDUINO_ARCH_NRF5) && (defined(NRF52_SERIES) || defined(NRF53_SERIES)) */ 65 | -------------------------------------------------------------------------------- /src/nimble/nimble/drivers/nrf5x/src/ble_phy_trace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #if defined(ARDUINO_ARCH_NRF5) && (defined(NRF52_SERIES) || defined(NRF53_SERIES)) 21 | 22 | #include 23 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 24 | #include "nimble/porting/nimble/include/os/os_trace_api.h" 25 | 26 | #if MYNEWT_VAL(BLE_PHY_SYSVIEW) 27 | 28 | static os_trace_module_t g_ble_phy_trace_mod; 29 | uint32_t ble_phy_trace_off; 30 | 31 | static void 32 | ble_phy_trace_module_send_desc(void) 33 | { 34 | os_trace_module_desc(&g_ble_phy_trace_mod, "0 phy_set_tx cputime=%u usecs=%u"); 35 | os_trace_module_desc(&g_ble_phy_trace_mod, "1 phy_set_rx cputime=%u usecs=%u"); 36 | os_trace_module_desc(&g_ble_phy_trace_mod, "2 phy_disable"); 37 | } 38 | 39 | void 40 | ble_phy_trace_init(void) 41 | { 42 | ble_phy_trace_off = 43 | os_trace_module_register(&g_ble_phy_trace_mod, "ble_phy", 3, 44 | ble_phy_trace_module_send_desc); 45 | } 46 | #endif 47 | 48 | #endif /* defined(ARDUINO_ARCH_NRF5) && (defined(NRF52_SERIES) || defined(NRF53_SERIES)) */ 49 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/include/host/ble_aes_ccm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0 5 | */ 6 | 7 | #ifndef _BLE_AES_CCM_ 8 | #define _BLE_AES_CCM_ 9 | 10 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 11 | #include "nimble/porting/nimble/include/os/queue.h" 12 | #include "nimble/nimble/host/include/host/ble_hs.h" 13 | 14 | #if MYNEWT_VAL(BLE_CRYPTO_STACK_MBEDTLS) 15 | #include "nimble/ext/tinycrypt/include/tinycrypt/aes.h" 16 | #else 17 | #include "nimble/ext/tinycrypt/include/tinycrypt/aes.h" 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #if MYNEWT_VAL(ENC_ADV_DATA) 25 | 26 | const char *ble_aes_ccm_hex(const void *buf, size_t len); 27 | int ble_aes_ccm_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *enc_data); 28 | int ble_aes_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *enc_data, 29 | size_t len, const uint8_t *aad, size_t aad_len, 30 | uint8_t *plaintext, size_t mic_size); 31 | int ble_aes_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *enc_data, 32 | size_t len, const uint8_t *aad, size_t aad_len, 33 | uint8_t *plaintext, size_t mic_size); 34 | 35 | #endif /* ENC_ADV_DATA */ 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* _BLE_AES_CCM_ */ 42 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/include/host/ble_esp_gatt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0 5 | */ 6 | 7 | #ifndef H_BLE_ESP_GATT_ 8 | #define H_BLE_ESP_GATT_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /** 15 | * Resets the GATT configuration parameters and deallocates the memory of attributes. 16 | * 17 | */ 18 | void ble_gatts_stop(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/include/host/ble_esp_hs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0 5 | */ 6 | 7 | #ifndef H_BLE_ESP_HS_ 8 | #define H_BLE_ESP_HS_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /** 15 | * Deinitializes the NimBLE host. This function must be called after the 16 | * NimBLE host stop procedure is complete. 17 | */ 18 | void ble_hs_deinit(void); 19 | 20 | #if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK) 21 | /** 22 | * Initializes the Bluetooth advertising list and associated mutex lock. 23 | */ 24 | void ble_adv_list_init(void); 25 | 26 | /** 27 | * Deinitializes the Bluetooth advertising list, releasing allocated memory and resources. 28 | */ 29 | void ble_adv_list_deinit(void); 30 | 31 | /** 32 | * Adds a Bluetooth advertising packet to the list. 33 | */ 34 | void ble_adv_list_add_packet(void *data); 35 | 36 | /** 37 | * Returns the count of Bluetooth advertising packets in the list. 38 | */ 39 | uint32_t ble_get_adv_list_length(void); 40 | 41 | /** 42 | * Clears and refreshes the Bluetooth advertising list. 43 | */ 44 | void ble_adv_list_refresh(void); 45 | 46 | /** 47 | * Checks if a Bluetooth address is present in the advertising list; if not, adds it to the list. 48 | */ 49 | bool ble_check_adv_list(const uint8_t *addr, uint8_t addr_type); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/include/host/ble_hs_mbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_MBUF_ 21 | #define H_BLE_HS_MBUF_ 22 | 23 | /** 24 | * @brief Bluetooth Host chained memory buffer (mbuf) 25 | * @defgroup bt_host_mbuf Bluetooth Host chained memory buffer (mbuf) 26 | * @ingroup bt_host 27 | * @{ 28 | */ 29 | 30 | #include 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | struct os_mbuf; 36 | 37 | /** 38 | * Allocates an mbuf suitable for an ATT command packet. The resulting packet 39 | * has sufficient leading space for: 40 | * - ACL data header 41 | * - L2CAP B-frame header 42 | * - Largest ATT command base (prepare write request / response). 43 | * 44 | * @return An empty mbuf on success, NULL on error. 45 | */ 46 | struct os_mbuf *ble_hs_mbuf_att_pkt(void); 47 | 48 | /** 49 | * Allocates an mbuf and fills it with the contents of the specified flat 50 | * buffer. 51 | * 52 | * @param buf The flat buffer to copy from. 53 | * @param len The length of the flat buffer. 54 | * 55 | * @return A newly-allocated mbuf on success, NULL on error. 56 | */ 57 | struct os_mbuf *ble_hs_mbuf_from_flat(const void *buf, uint16_t len); 58 | 59 | /** 60 | * Copies the contents of an mbuf into the specified flat buffer. If the flat 61 | * buffer is too small to contain the mbuf's contents, it is filled to capacity 62 | * and BLE_HS_EMSGSIZE is returned. 63 | * 64 | * @param om The mbuf to copy from. 65 | * @param flat The destination flat buffer. 66 | * @param max_len The size of the flat buffer. 67 | * @param out_copy_len The number of bytes actually copied gets written here. 68 | * 69 | * @return 0 on success or BLE host core return code on error. 70 | */ 71 | int ble_hs_mbuf_to_flat(const struct os_mbuf *om, void *flat, uint16_t max_len, 72 | uint16_t *out_copy_len); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/include/host/ble_ibeacon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_IBEACON_ 21 | #define H_BLE_IBEACON_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, 28 | uint16_t minor, int8_t measured_power); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/cfg_srv.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief Bluetooth Mesh Configuration Server Model APIs. 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2017 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | #ifndef __BT_MESH_CFG_SRV_H 11 | #define __BT_MESH_CFG_SRV_H 12 | 13 | /** 14 | * @brief Bluetooth Mesh 15 | * @defgroup bt_mesh_cfg_srv Bluetooth Mesh Configuration Server Model 16 | * @ingroup bt_mesh 17 | * @{ 18 | */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; 26 | extern const struct bt_mesh_model_cb bt_mesh_cfg_srv_cb; 27 | 28 | #define BT_MESH_MODEL_CFG_SRV \ 29 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_op, NULL, \ 30 | NULL, &bt_mesh_cfg_srv_cb) 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | /** 37 | * @} 38 | */ 39 | 40 | #endif /* __BT_MESH_CFG_SRV_H */ 41 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/health_cli.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief Bluetooth Mesh Health Client Model APIs. 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2017 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | #ifndef __BT_MESH_HEALTH_CLI_H 11 | #define __BT_MESH_HEALTH_CLI_H 12 | 13 | /** 14 | * @brief Bluetooth Mesh 15 | * @defgroup bt_mesh_health_cli Bluetooth Mesh Health Client Model 16 | * @ingroup bt_mesh 17 | * @{ 18 | */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** Mesh Health Client Model Context */ 25 | struct bt_mesh_health_cli { 26 | struct bt_mesh_model *model; 27 | 28 | void (*current_status)(struct bt_mesh_health_cli *cli, uint16_t addr, 29 | uint8_t test_id, uint16_t cid, uint8_t *faults, 30 | size_t fault_count); 31 | 32 | struct bt_mesh_msg_ack_ctx ack_ctx; 33 | }; 34 | 35 | extern const struct bt_mesh_model_op bt_mesh_health_cli_op[]; 36 | extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb; 37 | 38 | #define BT_MESH_MODEL_HEALTH_CLI(cli_data) \ 39 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_op, \ 40 | NULL, cli_data, &bt_mesh_health_cli_cb) 41 | 42 | int bt_mesh_health_cli_set(struct bt_mesh_model *model); 43 | 44 | int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid, 45 | uint8_t *test_id, uint8_t *faults, 46 | size_t *fault_count); 47 | 48 | int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid, 49 | uint8_t *test_id, uint8_t *faults, 50 | size_t *fault_count); 51 | 52 | int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid, 53 | uint8_t test_id, uint8_t *faults, 54 | size_t *fault_count); 55 | 56 | int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor); 57 | 58 | int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor, 59 | uint8_t *updated_divisor); 60 | 61 | int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *attention); 62 | 63 | int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx, uint8_t attention, 64 | uint8_t *updated_attention); 65 | 66 | int32_t bt_mesh_health_cli_timeout_get(void); 67 | void bt_mesh_health_cli_timeout_set(int32_t timeout); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | #endif /* __BT_MESH_HEALTH_CLI_H */ 78 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/mesh.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief Bluetooth Mesh Profile APIs. 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2017 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | #ifndef __BT_MESH_H 11 | #define __BT_MESH_H 12 | 13 | #include 14 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 15 | #include "nimble/porting/nimble/include/os/os_mbuf.h" 16 | 17 | #include "glue.h" 18 | #include "msg.h" 19 | #include "access.h" 20 | #include "main.h" 21 | #include "cfg.h" 22 | #include "cfg_srv.h" 23 | #include "health_srv.h" 24 | #include "cfg_cli.h" 25 | #include "health_cli.h" 26 | #include "proxy.h" 27 | #include "cdb.h" 28 | #include "cfg.h" 29 | #include "heartbeat.h" 30 | #include "nimble/nimble/host/mesh/src/app_keys.h" 31 | #include "nimble/nimble/host/mesh/src/net.h" 32 | 33 | #endif /* __BT_MESH_H */ 34 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/model_cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef __MODEL_CLI_H__ 8 | #define __MODEL_CLI_H__ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | struct bt_mesh_gen_model_cli { 15 | struct bt_mesh_model *model; 16 | 17 | struct k_sem op_sync; 18 | uint32_t op_pending; 19 | void *op_param; 20 | }; 21 | 22 | extern const struct bt_mesh_model_op gen_onoff_cli_op[]; 23 | extern const struct bt_mesh_model_cb bt_mesh_gen_onoff_cli_cb; 24 | 25 | #define BT_MESH_MODEL_GEN_ONOFF_CLI(cli_data, pub) \ 26 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_ONOFF_CLI, gen_onoff_cli_op, pub,\ 27 | cli_data, &bt_mesh_gen_onoff_cli_cb) 28 | 29 | extern const struct bt_mesh_model_op gen_level_cli_op[]; 30 | extern const struct bt_mesh_model_cb bt_mesh_gen_level_cli_cb; 31 | 32 | #define BT_MESH_MODEL_GEN_LEVEL_CLI(cli_data, pub) \ 33 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_LEVEL_CLI, gen_level_cli_op, pub,\ 34 | cli_data, &bt_mesh_gen_level_cli_cb) 35 | 36 | int bt_mesh_gen_onoff_get(uint16_t net_idx, uint16_t addr, uint16_t app_idx, 37 | uint8_t *state); 38 | int bt_mesh_gen_onoff_set(uint16_t net_idx, uint16_t addr, uint16_t app_idx, 39 | uint8_t val, uint8_t *state); 40 | int bt_mesh_gen_level_get(uint16_t net_idx, uint16_t addr, uint16_t app_idx, 41 | int16_t *level); 42 | int bt_mesh_gen_level_set(uint16_t net_idx, uint16_t addr, uint16_t app_idx, 43 | int16_t val, int16_t *state); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* __MODEL_CLI_H__ */ 50 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/model_srv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef __MODEL_SRV_H__ 8 | #define __MODEL_SRV_H__ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | struct bt_mesh_gen_onoff_srv { 15 | struct bt_mesh_model *model; 16 | 17 | int (*get)(struct bt_mesh_model *model, uint8_t *state); 18 | int (*set)(struct bt_mesh_model *model, uint8_t state); 19 | }; 20 | 21 | extern const struct bt_mesh_model_op gen_onoff_srv_op[]; 22 | extern const struct bt_mesh_model_cb gen_onoff_srv_cb; 23 | 24 | #define BT_MESH_MODEL_GEN_ONOFF_SRV(srv, pub) \ 25 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_ONOFF_SRV, \ 26 | gen_onoff_srv_op, pub, srv, &gen_onoff_srv_cb) 27 | 28 | struct bt_mesh_gen_level_srv { 29 | struct bt_mesh_model *model; 30 | 31 | int (*get)(struct bt_mesh_model *model, int16_t *level); 32 | int (*set)(struct bt_mesh_model *model, int16_t level); 33 | }; 34 | 35 | extern const struct bt_mesh_model_op gen_level_srv_op[]; 36 | extern const struct bt_mesh_model_cb gen_level_srv_cb; 37 | 38 | #define BT_MESH_MODEL_GEN_LEVEL_SRV(srv, pub) \ 39 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_LEVEL_SRV, \ 40 | gen_level_srv_op, pub, srv, &gen_level_srv_cb) 41 | 42 | struct bt_mesh_light_lightness_srv { 43 | struct bt_mesh_model *model; 44 | 45 | int (*get)(struct bt_mesh_model *model, int16_t *level); 46 | int (*set)(struct bt_mesh_model *model, int16_t level); 47 | }; 48 | 49 | extern const struct bt_mesh_model_op light_lightness_srv_op[]; 50 | extern const struct bt_mesh_model_cb light_lightness_srv_cb; 51 | 52 | #define BT_MESH_MODEL_LIGHT_LIGHTNESS_SRV(srv, pub) \ 53 | BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, \ 54 | light_lightness_srv_op, pub, srv, &light_lightness_srv_cb) 55 | 56 | void bt_mesh_set_gen_onoff_srv_cb(int (*get)(struct bt_mesh_model *model, uint8_t *state), 57 | int (*set)(struct bt_mesh_model *model, uint8_t state)); 58 | void bt_mesh_set_gen_level_srv_cb(int (*get)(struct bt_mesh_model *model, int16_t *level), 59 | int (*set)(struct bt_mesh_model *model, int16_t level)); 60 | void bt_mesh_set_light_lightness_srv_cb(int (*get)(struct bt_mesh_model *model, int16_t *level), 61 | int (*set)(struct bt_mesh_model *model, int16_t level)); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __MODEL_SRV_H__ */ 68 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/porting.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief Bluetooth Mesh Porting APIs. 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2017 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | #ifndef __BT_MESH_PORTING_H 11 | #define __BT_MESH_PORTING_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void mesh_adv_thread(void *args); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | /** 24 | * @} 25 | */ 26 | 27 | #endif /* __BT_MESH_PORTING_H */ 28 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/include/mesh/proxy.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief Bluetooth Mesh Proxy APIs. 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2017 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | #ifndef __BT_MESH_PROXY_H 11 | #define __BT_MESH_PROXY_H 12 | 13 | /** 14 | * @brief Bluetooth Mesh Proxy 15 | * @defgroup bt_mesh_proxy Bluetooth Mesh Proxy 16 | * @ingroup bt_mesh 17 | * @{ 18 | */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * @brief Enable advertising with Node Identity. 26 | * 27 | * This API requires that GATT Proxy support has been enabled. Once called 28 | * each subnet will start advertising using Node Identity for the next 29 | * 60 seconds. 30 | * 31 | * @return 0 on success, or (negative) error code on failure. 32 | */ 33 | int bt_mesh_proxy_identity_enable(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | #endif /* __BT_MESH_PROXY_H */ 44 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/app_keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Nordic Semiconductor ASA 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef _BT_MESH_APP_KEYS_H_ 8 | #define _BT_MESH_APP_KEYS_H_ 9 | 10 | #include "nimble/nimble/host/mesh/include/mesh/mesh.h" 11 | #include "subnet.h" 12 | 13 | /** @brief Reset the app keys module. */ 14 | void bt_mesh_app_keys_reset(void); 15 | 16 | /** @brief Initialize a new application key with the given parameters. 17 | * 18 | * @param app_idx AppIndex. 19 | * @param net_idx NetIndex the application is bound to. 20 | * @param old_key Current application key. 21 | * @param new_key Updated application key, or NULL if not known. 22 | * 23 | * @return 0 on success, or (negative) error code on failure. 24 | */ 25 | int bt_mesh_app_key_set(uint16_t app_idx, uint16_t net_idx, 26 | const uint8_t old_key[16], const uint8_t new_key[16]); 27 | 28 | /** @brief Resolve the message encryption keys, given a message context. 29 | * 30 | * Will use the @c ctx::app_idx and @c ctx::net_idx fields to find a pair of 31 | * message encryption keys. If @c ctx::app_idx represents a device key, the 32 | * @c ctx::net_idx will be used to determine the net key. Otherwise, the 33 | * @c ctx::net_idx parameter will be ignored. 34 | * 35 | * @param ctx Message context. 36 | * @param sub Subnet return parameter. 37 | * @param app_key Application return parameter. 38 | * @param aid Application ID return parameter. 39 | * 40 | * @return 0 on success, or (negative) error code on failure. 41 | */ 42 | int bt_mesh_keys_resolve(struct bt_mesh_msg_ctx *ctx, 43 | struct bt_mesh_subnet **sub, 44 | const uint8_t **app_key, uint8_t *aid); 45 | 46 | /** @brief Iterate through all matching application keys and call @c cb on each. 47 | * 48 | * @param dev_key Whether to return device keys. 49 | * @param aid 7 bit application ID to match. 50 | * @param rx RX structure to match against. 51 | * @param cb Callback to call for every valid app key. 52 | * @param cb_data Callback data to pass to the callback. 53 | * 54 | * @return The AppIdx that yielded a 0-return from the callback. 55 | */ 56 | uint16_t bt_mesh_app_key_find(bool dev_key, uint8_t aid, 57 | struct bt_mesh_net_rx *rx, 58 | int (*cb)(struct bt_mesh_net_rx *rx, 59 | const uint8_t key[16], void *cb_data), 60 | void *cb_data); 61 | 62 | extern void (*bt_mesh_app_key_cb_list[1]) (uint16_t app_idx, uint16_t net_idx, 63 | enum bt_mesh_key_evt evt); 64 | 65 | /** @brief Store pending application keys in persistent storage. */ 66 | void bt_mesh_app_key_pending_store(void); 67 | void bt_mesh_app_key_init(void); 68 | #endif /* _BT_MESH_APP_KEYS_H_ */ 69 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/beacon.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | #ifndef __BEACON_H__ 10 | #define __BEACON_H__ 11 | 12 | #include "nimble/porting/nimble/include/os/os_mbuf.h" 13 | 14 | void bt_mesh_beacon_enable(void); 15 | void bt_mesh_beacon_disable(void); 16 | 17 | void bt_mesh_beacon_ivu_initiator(bool enable); 18 | 19 | void bt_mesh_beacon_recv(struct os_mbuf *buf); 20 | 21 | void bt_mesh_beacon_create(struct bt_mesh_subnet *sub, 22 | struct os_mbuf *buf); 23 | 24 | void bt_mesh_beacon_init(void); 25 | void bt_mesh_beacon_update(struct bt_mesh_subnet *sub); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/cdb_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Nordic Semiconductor ASA 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /* ommitted `bt_mesh_cdb_node_store` declaration - every header 8 | * includes mesh/mesh.h, which already has it 9 | * void bt_mesh_cdb_node_store(const struct bt_mesh_cdb_node *node); 10 | */ 11 | void bt_mesh_cdb_pending_store(void); 12 | void bt_mesh_cdb_init(void); 13 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Nordic Semiconductor ASA 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | void bt_mesh_cfg_default_set(void); 8 | void bt_mesh_cfg_pending_store(void); 9 | 10 | bool bt_mesh_fixed_group_match(uint16_t addr); 11 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/friend.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | #ifndef __FRIEND_H__ 10 | #define __FRIEND_H__ 11 | 12 | #include "nimble/nimble/host/mesh/include/mesh/mesh.h" 13 | 14 | enum bt_mesh_friend_pdu_type { 15 | BT_MESH_FRIEND_PDU_SINGLE, 16 | BT_MESH_FRIEND_PDU_PARTIAL, 17 | BT_MESH_FRIEND_PDU_COMPLETE, 18 | }; 19 | 20 | bool bt_mesh_friend_match(uint16_t net_idx, uint16_t addr); 21 | 22 | struct bt_mesh_friend *bt_mesh_friend_find(uint16_t net_idx, uint16_t lpn_addr, 23 | bool valid, bool established); 24 | 25 | bool bt_mesh_friend_queue_has_space(uint16_t net_idx, uint16_t src, uint16_t dst, 26 | uint64_t *seq_auth, uint8_t seg_count); 27 | 28 | void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx, 29 | enum bt_mesh_friend_pdu_type type, 30 | uint64_t *seq_auth, uint8_t seg_count, 31 | struct os_mbuf *sbuf); 32 | bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx, 33 | enum bt_mesh_friend_pdu_type type, 34 | uint64_t *seq_auth, uint8_t seg_count, 35 | struct os_mbuf *sbuf); 36 | 37 | void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, uint16_t src, 38 | uint16_t dst, uint64_t *seq_auth); 39 | 40 | void bt_mesh_friend_sec_update(uint16_t net_idx); 41 | 42 | void bt_mesh_friends_clear(void); 43 | 44 | int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct os_mbuf *buf); 45 | int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct os_mbuf *buf); 46 | int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct os_mbuf *buf); 47 | int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx, 48 | struct os_mbuf *buf); 49 | int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx, 50 | struct os_mbuf *buf); 51 | int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx, 52 | struct os_mbuf *buf); 53 | 54 | int bt_mesh_friend_init(void); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/heartbeat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Nordic Semiconductor ASA 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "nimble/nimble/host/mesh/include/mesh/heartbeat.h" 8 | 9 | static inline uint16_t bt_mesh_hb_pwr2(uint8_t val) 10 | { 11 | if (!val) { 12 | return 0x0000; 13 | } else if (val == 0xff || val == 0x11) { 14 | return 0xffff; 15 | } else { 16 | return (1 << (val - 1)); 17 | } 18 | } 19 | 20 | static inline uint8_t bt_mesh_hb_log(uint32_t val) 21 | { 22 | if (!val) { 23 | return 0x00; 24 | } else if (val == 0xffff) { 25 | return 0xff; 26 | } else { 27 | return 32 - __builtin_clz(val); 28 | } 29 | } 30 | 31 | void bt_mesh_hb_init(void); 32 | void bt_mesh_hb_start(void); 33 | void bt_mesh_hb_suspend(void); 34 | void bt_mesh_hb_resume(void); 35 | 36 | int bt_mesh_hb_recv(struct bt_mesh_net_rx *rx, struct os_mbuf *buf); 37 | void bt_mesh_hb_feature_changed(uint16_t features); 38 | 39 | uint8_t bt_mesh_hb_pub_set(struct bt_mesh_hb_pub *hb_pub); 40 | uint8_t bt_mesh_hb_sub_set(uint16_t src, uint16_t dst, uint32_t period); 41 | void bt_mesh_hb_sub_reset_count(void); 42 | void bt_mesh_hb_pub_pending_store(void); 43 | void bt_mesh_hb_pub_init(void); 44 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/light_model.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 8 | 9 | #include "nimble/nimble/host/mesh/include/mesh/mesh.h" 10 | #include "nimble/console/console.h" 11 | #include "light_model.h" 12 | 13 | 14 | static uint8_t gen_onoff_state; 15 | static int16_t gen_level_state; 16 | 17 | static void update_light_state(void) 18 | { 19 | console_printf("Light state: onoff=%d lvl=0x%04x\n", gen_onoff_state, (uint16_t)gen_level_state); 20 | } 21 | 22 | int light_model_gen_onoff_get(struct bt_mesh_model *model, uint8_t *state) 23 | { 24 | *state = gen_onoff_state; 25 | return 0; 26 | } 27 | 28 | int light_model_gen_onoff_set(struct bt_mesh_model *model, uint8_t state) 29 | { 30 | gen_onoff_state = state; 31 | update_light_state(); 32 | return 0; 33 | } 34 | 35 | int light_model_gen_level_get(struct bt_mesh_model *model, int16_t *level) 36 | { 37 | *level = gen_level_state; 38 | return 0; 39 | } 40 | 41 | int light_model_gen_level_set(struct bt_mesh_model *model, int16_t level) 42 | { 43 | gen_level_state = level; 44 | if ((uint16_t)gen_level_state > 0x0000) { 45 | gen_onoff_state = 1; 46 | } 47 | if ((uint16_t)gen_level_state == 0x0000) { 48 | gen_onoff_state = 0; 49 | } 50 | update_light_state(); 51 | return 0; 52 | } 53 | 54 | int light_model_light_lightness_get(struct bt_mesh_model *model, int16_t *lightness) 55 | { 56 | return light_model_gen_level_get(model, lightness); 57 | } 58 | 59 | int light_model_light_lightness_set(struct bt_mesh_model *model, int16_t lightness) 60 | { 61 | return light_model_gen_level_set(model, lightness); 62 | } 63 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/light_model.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #ifndef __BT_MESH_LIGHT_MODEL_H 7 | #define __BT_MESH_LIGHT_MODEL_H 8 | 9 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 10 | #include "nimble/nimble/host/mesh/include/mesh/mesh.h" 11 | 12 | int light_model_gen_onoff_get(struct bt_mesh_model *model, uint8_t *state); 13 | int light_model_gen_onoff_set(struct bt_mesh_model *model, uint8_t state); 14 | int light_model_gen_level_get(struct bt_mesh_model *model, int16_t *level); 15 | int light_model_gen_level_set(struct bt_mesh_model *model, int16_t level); 16 | int light_model_light_lightness_get(struct bt_mesh_model *model, int16_t *lightness); 17 | int light_model_light_lightness_set(struct bt_mesh_model *model, int16_t lightness); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/lpn.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | #ifndef __LPN_H__ 9 | #define __LPN_H__ 10 | 11 | #include "nimble/nimble/host/mesh/include/mesh/mesh.h" 12 | 13 | int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, 14 | struct os_mbuf *buf); 15 | int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, 16 | struct os_mbuf *buf); 17 | int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx, 18 | struct os_mbuf *buf); 19 | int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx, 20 | struct os_mbuf *buf); 21 | 22 | static inline bool bt_mesh_lpn_established(void) 23 | { 24 | #if (MYNEWT_VAL(BLE_MESH_LOW_POWER)) 25 | return bt_mesh.lpn.established; 26 | #else 27 | return false; 28 | #endif 29 | } 30 | 31 | static inline bool bt_mesh_lpn_match(uint16_t addr) 32 | { 33 | #if (MYNEWT_VAL(BLE_MESH_LOW_POWER)) 34 | if (bt_mesh_lpn_established()) { 35 | return (addr == bt_mesh.lpn.frnd); 36 | } 37 | #endif 38 | return false; 39 | } 40 | 41 | static inline bool bt_mesh_lpn_waiting_update(void) 42 | { 43 | #if (MYNEWT_VAL(BLE_MESH_LOW_POWER)) 44 | return (bt_mesh.lpn.state == BT_MESH_LPN_WAIT_UPDATE); 45 | #else 46 | return false; 47 | #endif 48 | } 49 | 50 | void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx); 51 | 52 | void bt_mesh_lpn_group_add(uint16_t group); 53 | void bt_mesh_lpn_group_del(uint16_t *groups, size_t group_count); 54 | 55 | void bt_mesh_lpn_disable(bool force); 56 | 57 | int bt_mesh_lpn_init(void); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/mesh_priv.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | #ifndef __MESH_PRIV_H 9 | #define __MESH_PRIV_H 10 | 11 | #include 12 | #include 13 | 14 | #define BT_MESH_KEY_PRIMARY 0x0000 15 | #define BT_MESH_KEY_ANY 0xffff 16 | 17 | enum bt_mesh_key_evt { 18 | BT_MESH_KEY_ADDED, /* New key added */ 19 | BT_MESH_KEY_DELETED, /* Existing key deleted */ 20 | BT_MESH_KEY_UPDATED, /* KR phase 1, second key added */ 21 | BT_MESH_KEY_SWAPPED, /* KR phase 2, now sending on second key */ 22 | BT_MESH_KEY_REVOKED, /* KR phase 3, old key removed */ 23 | }; 24 | 25 | /** Appkey callback. Instantiate with @ref BT_MESH_APP_KEY_CB */ 26 | struct bt_mesh_app_key_cb { 27 | void (*evt_handler)(uint16_t app_idx, uint16_t net_idx, 28 | enum bt_mesh_key_evt evt); 29 | }; 30 | 31 | struct bt_mesh_net; 32 | int bt_mesh_start(void); 33 | 34 | #define OP_GEN_ONOFF_GET BT_MESH_MODEL_OP_2(0x82, 0x01) 35 | #define OP_GEN_ONOFF_SET BT_MESH_MODEL_OP_2(0x82, 0x02) 36 | #define OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03) 37 | #define OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04) 38 | #define OP_GEN_LEVEL_GET BT_MESH_MODEL_OP_2(0x82, 0x05) 39 | #define OP_GEN_LEVEL_SET BT_MESH_MODEL_OP_2(0x82, 0x06) 40 | #define OP_GEN_LEVEL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x07) 41 | #define OP_GEN_LEVEL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x08) 42 | #define OP_GEN_DELTA_SET BT_MESH_MODEL_OP_2(0x82, 0x09) 43 | #define OP_GEN_DELTA_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0a) 44 | #define OP_GEN_MOVE_SET BT_MESH_MODEL_OP_2(0x82, 0x0b) 45 | #define OP_GEN_MOVE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0c) 46 | #define OP_LIGHT_LIGHTNESS_GET BT_MESH_MODEL_OP_2(0x82, 0x4b) 47 | #define OP_LIGHT_LIGHTNESS_SET BT_MESH_MODEL_OP_2(0x82, 0x4c) 48 | #define OP_LIGHT_LIGHTNESS_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x4d) 49 | #define OP_LIGHT_LIGHTNESS_STATUS BT_MESH_MODEL_OP_2(0x82, 0x4e) 50 | 51 | bool bt_mesh_is_provisioned(void); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/msg.c: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2021 Nordic Semiconductor ASA 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | #include "nimble/nimble/host/mesh/include/mesh/mesh.h" 10 | 11 | void bt_mesh_model_msg_init(struct os_mbuf *msg, uint32_t opcode) 12 | { 13 | net_buf_simple_init(msg, 0); 14 | 15 | switch (BT_MESH_MODEL_OP_LEN(opcode)) { 16 | case 1: 17 | net_buf_simple_add_u8(msg, opcode); 18 | break; 19 | case 2: 20 | net_buf_simple_add_be16(msg, opcode); 21 | break; 22 | case 3: 23 | net_buf_simple_add_u8(msg, ((opcode >> 16) & 0xff)); 24 | /* Using LE for the CID since the model layer is defined as 25 | * little-endian in the mesh spec and using BT_MESH_MODEL_OP_3 26 | * will declare the opcode in this way. 27 | */ 28 | net_buf_simple_add_le16(msg, opcode & 0xffff); 29 | break; 30 | default: 31 | BT_WARN("Unknown opcode format"); 32 | break; 33 | } 34 | } 35 | 36 | void bt_mesh_msg_ack_ctx_clear(struct bt_mesh_msg_ack_ctx *ack) 37 | { 38 | ack->op = 0U; 39 | ack->user_data = NULL; 40 | ack->dst = BT_MESH_ADDR_UNASSIGNED; 41 | } 42 | 43 | int bt_mesh_msg_ack_ctx_prepare(struct bt_mesh_msg_ack_ctx *ack, 44 | uint32_t op, uint16_t dst, void *user_data) 45 | { 46 | if (ack->op) { 47 | BT_WARN("Another synchronous operation pending"); 48 | return -EBUSY; 49 | } 50 | 51 | ack->op = op; 52 | ack->user_data = user_data; 53 | ack->dst = dst; 54 | 55 | return 0; 56 | } 57 | 58 | int bt_mesh_msg_ack_ctx_wait(struct bt_mesh_msg_ack_ctx *ack, int32_t timeout) 59 | { 60 | int err; 61 | 62 | err = k_sem_take(&ack->sem, timeout); 63 | bt_mesh_msg_ack_ctx_clear(ack); 64 | 65 | if (err == -EAGAIN) { 66 | return -ETIMEDOUT; 67 | } 68 | 69 | return err; 70 | } 71 | 72 | bool bt_mesh_msg_ack_ctx_match(const struct bt_mesh_msg_ack_ctx *ack, 73 | uint32_t op, uint16_t addr, void **user_data) 74 | { 75 | if (ack->op != op || (BT_MESH_ADDR_IS_UNICAST(ack->dst) && ack->dst != addr)) { 76 | return false; 77 | } 78 | 79 | if (user_data != NULL) { 80 | *user_data = ack->user_data; 81 | } 82 | 83 | return true; 84 | } 85 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/pb_gatt_srv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * Copyright (c) 2021 Lingao Meng 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #ifndef __PB_GATT_SRV_H__ 9 | #define __PB_GATT_SRV_H__ 10 | 11 | int bt_mesh_pb_gatt_send(uint16_t conn_handle, struct os_mbuf *buf); 12 | 13 | int bt_mesh_pb_gatt_enable(void); 14 | int bt_mesh_pb_gatt_disable(void); 15 | 16 | int prov_ccc_write(uint16_t conn_handle, uint8_t type); 17 | void gatt_disconnected_pb_gatt(struct ble_gap_conn_desc conn, uint8_t err); 18 | void gatt_connected_pb_gatt(uint16_t conn_handle, uint8_t err); 19 | void resolve_svc_handles(void); 20 | 21 | int bt_mesh_pb_gatt_adv_start(void); 22 | 23 | extern struct svc_handles { 24 | uint16_t proxy_h; 25 | uint16_t proxy_data_out_h; 26 | uint16_t prov_h; 27 | uint16_t prov_data_in_h; 28 | uint16_t prov_data_out_h; 29 | } svc_handles; 30 | 31 | #endif /* __PB_GATT_SRV_H__ */ 32 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/provisioner.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | int bt_mesh_pb_adv_open(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr, 10 | uint8_t attention_duration); 11 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/proxy.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | #ifndef __PROXY_H__ 10 | #define __PROXY_H__ 11 | 12 | #include "nimble/nimble/host/mesh/include/mesh/slist.h" 13 | 14 | #if CONFIG_BT_MESH_DEBUG_USE_ID_ADDR 15 | #define ADV_OPT_USE_IDENTITY BT_LE_ADV_OPT_USE_IDENTITY 16 | #else 17 | #define ADV_OPT_USE_IDENTITY 0 18 | #endif 19 | 20 | #define ADV_SLOW_INT \ 21 | .itvl_min = BT_GAP_ADV_SLOW_INT_MIN, \ 22 | .itvl_max = BT_GAP_ADV_SLOW_INT_MAX, 23 | 24 | #define ADV_FAST_INT \ 25 | .itvl_min = BT_GAP_ADV_FAST_INT_MIN_2, \ 26 | .itvl_max = BT_GAP_ADV_FAST_INT_MAX_2, 27 | 28 | struct bt_mesh_proxy_idle_cb { 29 | sys_snode_t n; 30 | void (*cb)(void); 31 | }; 32 | 33 | void notify_complete(void); 34 | int bt_mesh_proxy_gatt_enable(void); 35 | int bt_mesh_proxy_gatt_disable(void); 36 | void bt_mesh_proxy_gatt_disconnect(void); 37 | 38 | void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub); 39 | 40 | int bt_mesh_proxy_adv_start(void); 41 | 42 | void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub); 43 | void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub); 44 | 45 | bool bt_mesh_proxy_relay(struct os_mbuf *buf, uint16_t dst); 46 | void bt_mesh_proxy_addr_add(struct os_mbuf *buf, uint16_t addr); 47 | 48 | int ble_mesh_proxy_gap_event(struct ble_gap_event *event, void *arg); 49 | int bt_mesh_proxy_init(void); 50 | 51 | #endif /* __PROXY_H__ */ 52 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/proxy_msg.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * Copyright (c) 2021 Lingao Meng 6 | * 7 | * SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | #ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_ 11 | #define ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_ 12 | 13 | #define PDU_TYPE(data) (data[0] & BIT_MASK(6)) 14 | #define CFG_FILTER_SET 0x00 15 | #define CFG_FILTER_ADD 0x01 16 | #define CFG_FILTER_REMOVE 0x02 17 | #define CFG_FILTER_STATUS 0x03 18 | 19 | #define BT_MESH_PROXY_NET_PDU 0x00 20 | #define BT_MESH_PROXY_BEACON 0x01 21 | #define BT_MESH_PROXY_CONFIG 0x02 22 | #define BT_MESH_PROXY_PROV 0x03 23 | 24 | #define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6))) 25 | 26 | struct bt_mesh_proxy_role; 27 | 28 | typedef int (*proxy_send_cb_t)(uint16_t conn_handle, 29 | const void *data, uint16_t len); 30 | 31 | typedef void (*proxy_recv_cb_t)(struct bt_mesh_proxy_role *role); 32 | 33 | struct bt_mesh_proxy_role { 34 | uint16_t conn_handle; 35 | uint8_t msg_type; 36 | 37 | struct { 38 | proxy_send_cb_t send; 39 | proxy_recv_cb_t recv; 40 | } cb; 41 | 42 | struct k_work_delayable sar_timer; 43 | struct os_mbuf *buf; 44 | }; 45 | 46 | struct bt_mesh_proxy_client { 47 | struct bt_mesh_proxy_role *cli; 48 | uint16_t conn_handle; 49 | uint16_t filter[MYNEWT_VAL(BLE_MESH_PROXY_FILTER_SIZE)]; 50 | enum __packed { 51 | NONE, 52 | ACCEPT, 53 | REJECT, 54 | } filter_type; 55 | struct ble_npl_callout send_beacons; 56 | }; 57 | 58 | int bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role, 59 | const void *buf, uint16_t len); 60 | int bt_mesh_proxy_msg_send(struct bt_mesh_proxy_role *role, uint8_t type, struct os_mbuf *msg); 61 | void bt_mesh_proxy_msg_init(struct bt_mesh_proxy_role *role); 62 | void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role); 63 | struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(uint16_t conn_handle, 64 | proxy_send_cb_t send, 65 | proxy_recv_cb_t recv); 66 | struct bt_mesh_proxy_client *find_client(uint16_t conn_handle); 67 | #endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_ */ 68 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/rpl.h: -------------------------------------------------------------------------------- 1 | /* Bluetooth Mesh */ 2 | 3 | /* 4 | * Copyright (c) 2017 Intel Corporation 5 | * Copyright (c) 2020 Lingao Meng 6 | * 7 | * SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | struct bt_mesh_rpl { 11 | uint64_t src:15, 12 | old_iv:1, 13 | seq:24, 14 | /** Sequence authentication value for the previous segmented 15 | * message received from this address. 16 | * 17 | * This value is used to manage the parallel RPL of the 18 | * SeqAuth values in transport. 19 | */ 20 | seg:24; 21 | }; 22 | 23 | typedef void (*bt_mesh_rpl_func_t)(struct bt_mesh_rpl *rpl, 24 | void *user_data); 25 | 26 | void bt_mesh_rpl_reset(void); 27 | bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, 28 | struct bt_mesh_rpl **match); 29 | void bt_mesh_rpl_clear(void); 30 | void bt_mesh_rpl_update(struct bt_mesh_rpl *rpl, 31 | struct bt_mesh_net_rx *rx); 32 | void bt_mesh_rpl_init(void); 33 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | /* Pending storage actions. */ 7 | enum bt_mesh_settings_flag { 8 | BT_MESH_SETTINGS_RPL_PENDING, 9 | BT_MESH_SETTINGS_NET_KEYS_PENDING, 10 | BT_MESH_SETTINGS_APP_KEYS_PENDING, 11 | BT_MESH_SETTINGS_NET_PENDING, 12 | BT_MESH_SETTINGS_IV_PENDING, 13 | BT_MESH_SETTINGS_SEQ_PENDING, 14 | BT_MESH_SETTINGS_HB_PUB_PENDING, 15 | BT_MESH_SETTINGS_CFG_PENDING, 16 | BT_MESH_SETTINGS_MOD_PENDING, 17 | BT_MESH_SETTINGS_VA_PENDING, 18 | BT_MESH_SETTINGS_CDB_PENDING, 19 | 20 | BT_MESH_SETTINGS_FLAG_COUNT, 21 | }; 22 | 23 | void bt_mesh_settings_init(void); 24 | int settings_name_next(char *name, char **next); 25 | void bt_mesh_settings_store_schedule(enum bt_mesh_settings_flag flag); 26 | void bt_mesh_settings_store_cancel(enum bt_mesh_settings_flag flag); 27 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/shell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef __SHELL_H__ 8 | #define __SHELL_H__ 9 | 10 | void ble_mesh_shell_init(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/mesh/src/testing.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file testing.h 3 | * @brief Internal API for Bluetooth testing. 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2017 Intel Corporation 8 | * 9 | * SPDX-License-Identifier: Apache-2.0 10 | */ 11 | 12 | #include "nimble/nimble/host/mesh/include/mesh/glue.h" 13 | #include "nimble/nimble/host/mesh/include/mesh/access.h" 14 | 15 | void bt_test_mesh_model_bound(uint16_t addr, struct bt_mesh_model *model, 16 | uint16_t key_idx); 17 | void bt_test_mesh_model_unbound(uint16_t addr, struct bt_mesh_model *model, 18 | uint16_t key_idx); 19 | void bt_test_mesh_prov_invalid_bearer(uint8_t opcode); 20 | void bt_test_mesh_net_recv(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, 21 | const void *payload, size_t payload_len); 22 | void bt_test_mesh_trans_incomp_timer_exp(void); 23 | void bt_test_print_credentials(void); 24 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_SVC_GAP_ 21 | #define H_BLE_SVC_GAP_ 22 | 23 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 24 | #include 25 | #if MYNEWT_VAL(ENC_ADV_DATA) 26 | #include "nimble/nimble/host/include/host/ble_ead.h" 27 | #endif 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #define BLE_SVC_GAP_UUID16 0x1800 33 | #define BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME 0x2a00 34 | #define BLE_SVC_GAP_CHR_UUID16_APPEARANCE 0x2a01 35 | #define BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS 0x2a04 36 | #define BLE_SVC_GAP_CHR_UUID16_CENTRAL_ADDRESS_RESOLUTION 0x2aa6 37 | #define BLE_SVC_GAP_CHR_UUID16_LE_GATT_SECURITY_LEVELS 0x2BF5 38 | 39 | #if MYNEWT_VAL(ENC_ADV_DATA) 40 | #define BLE_SVC_GAP_CHR_UUID16_KEY_MATERIAL 0x2B88 41 | #endif 42 | 43 | #define BLE_SVC_GAP_APPEARANCE_GEN_UNKNOWN 0 44 | #define BLE_SVC_GAP_APPEARANCE_GEN_COMPUTER 128 45 | #define BLE_SVC_GAP_APPEARANCE_GEN_HID 960 46 | #define BLE_SVC_GAP_APPEARANCE_CYC_SPEED_AND_CADENCE_SENSOR 1157 47 | 48 | typedef void (ble_svc_gap_chr_changed_fn) (uint16_t uuid); 49 | 50 | void ble_svc_gap_set_chr_changed_cb(ble_svc_gap_chr_changed_fn *cb); 51 | 52 | const char *ble_svc_gap_device_name(void); 53 | int ble_svc_gap_device_name_set(const char *name); 54 | uint16_t ble_svc_gap_device_appearance(void); 55 | int ble_svc_gap_device_appearance_set(uint16_t appearance); 56 | #if MYNEWT_VAL(ENC_ADV_DATA) 57 | int ble_svc_gap_device_key_material_set(uint8_t *session_key, uint8_t *iv); 58 | #endif 59 | 60 | void ble_svc_gap_init(void); 61 | void ble_svc_gap_deinit(void); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_SVC_GATT_ 21 | #define H_BLE_SVC_GATT_ 22 | 23 | #include 24 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | struct ble_hs_cfg; 31 | 32 | #define BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16 0x2a05 33 | #define BLE_SVC_GATT_CHR_SERVER_SUPPORTED_FEAT_UUID16 0x2b3a 34 | #define BLE_SVC_GATT_CHR_CLIENT_SUPPORTED_FEAT_UUID16 0x2b29 35 | 36 | #define BLE_SVR_GATT_CHR_SVR_SUP_FEAT_EATT_FLAG 0x01 37 | 38 | #define BLE_SVR_GATT_CHR_CLT_SUP_FEAT_ROBUST_CACHING_FLAG 0x01 39 | #define BLE_SVR_GATT_CHR_CLT_SUP_FEAT_EATT_FLAG 0x02 40 | #define BLE_SVR_GATT_CHR_CLT_SUP_FEAT_MULTI_NOTIF_FLAG 0x04 41 | 42 | #if MYNEWT_VAL(BLE_GATT_CACHING) 43 | #define BLE_SVC_GATT_CHR_DATABASE_HASH_UUID16 0x2b2a 44 | 45 | uint16_t ble_svc_gatt_changed_handle(void); 46 | uint16_t ble_svc_gatt_hash_handle(void); 47 | uint16_t ble_svc_gatt_csf_handle(void); 48 | uint8_t ble_svc_gatt_get_csfs(void); 49 | #endif 50 | 51 | uint8_t ble_svc_gatt_get_local_cl_supported_feat(void); 52 | void ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle); 53 | void ble_svc_gatt_init(void); 54 | void ble_svc_gatt_deinit(void); 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_dtm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "ble_hs_hci_priv.h" 24 | 25 | int 26 | ble_dtm_rx_start(const struct ble_dtm_rx_params *params) 27 | { 28 | struct ble_hci_le_rx_test_v2_cp cmd; 29 | 30 | cmd.rx_chan = params->channel; 31 | cmd.phy = params->phy; 32 | cmd.index = params->modulation_index; 33 | 34 | return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE, 35 | BLE_HCI_OCF_LE_RX_TEST_V2), 36 | &cmd, sizeof(cmd), NULL, 0); 37 | } 38 | 39 | int 40 | ble_dtm_tx_start(const struct ble_dtm_tx_params *params) 41 | { 42 | struct ble_hci_le_tx_test_v2_cp cmd; 43 | 44 | cmd.tx_chan = params->channel; 45 | cmd.test_data_len = params->test_data_len; 46 | cmd.payload = params->payload; 47 | cmd.phy = params->phy; 48 | 49 | return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE, 50 | BLE_HCI_OCF_LE_TX_TEST_V2), 51 | &cmd, sizeof(cmd), NULL, 0); 52 | } 53 | 54 | int 55 | ble_dtm_stop(uint16_t *num_packets) 56 | { 57 | struct ble_hci_le_test_end_rp rsp; 58 | int rc; 59 | 60 | rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE, 61 | BLE_HCI_OCF_LE_TEST_END), 62 | NULL, 0, &rsp, sizeof(rsp)); 63 | 64 | if (rc) { 65 | *num_packets = 0; 66 | } else { 67 | *num_packets = le16toh(rsp.num_packets); 68 | } 69 | 70 | return rc; 71 | } 72 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_eatt_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 21 | #include "nimble/porting/nimble/include/os/os_mbuf.h" 22 | #include "nimble/nimble/host/include/host/ble_l2cap.h" 23 | 24 | #ifndef BLE_EATT_H_ 25 | #define BLE_EATT_H_ 26 | 27 | typedef int (* ble_eatt_att_rx_fn)(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rx_buf); 28 | 29 | #define BLE_EATT_PSM (0x0027) 30 | 31 | #define BLE_GATT_OP_SERVER 0xF1 32 | #define BLE_GATT_OP_DUMMY 0xF2 33 | 34 | #if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 35 | void ble_eatt_init(ble_eatt_att_rx_fn att_rx_fn); 36 | uint16_t ble_eatt_get_available_chan_cid(uint16_t conn_handle, uint8_t op); 37 | void ble_eatt_release_chan(uint16_t conn_handle, uint8_t op); 38 | int ble_eatt_tx(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txom); 39 | #else 40 | static inline void 41 | ble_eatt_init(ble_eatt_att_rx_fn att_rx_fn) 42 | { 43 | } 44 | 45 | static inline void 46 | ble_eatt_release_chan(uint16_t conn_handle, uint8_t op) 47 | { 48 | 49 | } 50 | 51 | static inline uint16_t 52 | ble_eatt_get_available_chan_cid(uint16_t conn_handle, uint8_t op) 53 | { 54 | return BLE_L2CAP_CID_ATT; 55 | } 56 | 57 | #endif 58 | #endif 59 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_adv_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_ADV_PRIV_ 21 | #define H_BLE_HS_ADV_PRIV_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data, 28 | uint8_t *dst, uint8_t *dst_len, uint8_t max_len); 29 | int ble_hs_adv_find_field(uint8_t type, const uint8_t *data, uint8_t length, 30 | const struct ble_hs_adv_field **out); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_atomic_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_ATOMIC_ 21 | #define H_BLE_HS_ATOMIC_ 22 | 23 | #include "ble_hs_conn_priv.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int ble_hs_atomic_conn_delete(uint16_t conn_handle); 30 | void ble_hs_atomic_conn_insert(struct ble_hs_conn *conn); 31 | int ble_hs_atomic_conn_flags(uint16_t conn_handle, 32 | ble_hs_conn_flags_t *out_flags); 33 | int ble_hs_atomic_conn_set_flags(uint16_t conn_handle, 34 | ble_hs_conn_flags_t flags, int on); 35 | uint16_t ble_hs_atomic_first_conn_handle(void); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_cfg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 21 | #include "nimble/nimble/host/include/host/ble_hs.h" 22 | 23 | struct ble_hs_cfg ble_hs_cfg = { 24 | /** Security manager settings. */ 25 | .sm_io_cap = MYNEWT_VAL(BLE_SM_IO_CAP), 26 | .sm_oob_data_flag = MYNEWT_VAL(BLE_SM_OOB_DATA_FLAG), 27 | .sm_bonding = MYNEWT_VAL(BLE_SM_BONDING), 28 | .sm_mitm = MYNEWT_VAL(BLE_SM_MITM), 29 | .sm_sc = MYNEWT_VAL(BLE_SM_SC), 30 | .sm_sc_only = MYNEWT_VAL(BLE_SM_SC_ONLY), 31 | .sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS), 32 | .sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST), 33 | .sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST), 34 | .eatt = MYNEWT_VAL(BLE_EATT_CHAN_NUM), 35 | }; 36 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_flow_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_FLOW_PRIV_ 21 | #define H_BLE_HS_FLOW_PRIV_ 22 | 23 | #include 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | void ble_hs_flow_connection_broken(uint16_t conn_handle); 29 | void ble_hs_flow_track_data_mbuf(struct os_mbuf *om); 30 | int ble_hs_flow_startup(void); 31 | void ble_hs_flow_stop(void); 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_id_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_ID_PRIV_ 21 | #define H_BLE_HS_ID_PRIV_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void ble_hs_id_set_pub(const uint8_t *pub_addr); 30 | int ble_hs_id_addr(uint8_t id_addr_type, const uint8_t **out_id_addr, 31 | int *out_is_nrpa); 32 | int ble_hs_id_use_addr(uint8_t addr_type); 33 | void ble_hs_id_reset(void); 34 | void ble_hs_id_rnd_reset(void); 35 | 36 | #if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY) 37 | bool ble_hs_is_rpa(uint8_t *addr, uint8_t addr_type); 38 | int ble_hs_id_set_pseudo_rnd(const uint8_t *); 39 | int ble_hs_id_set_nrpa_rnd(void); 40 | #endif 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "nimble/porting/nimble/include/os/os.h" 21 | #include "nimble/nimble/host/include/host/ble_hs.h" 22 | #include "nimble/nimble/host/include/host/ble_hs_log.h" 23 | 24 | struct log ble_hs_log; 25 | 26 | void 27 | ble_hs_log_mbuf(const struct os_mbuf *om) 28 | { 29 | uint8_t u8; 30 | int i; 31 | 32 | for (i = 0; i < OS_MBUF_PKTLEN(om); i++) { 33 | os_mbuf_copydata(om, i, 1, &u8); 34 | BLE_HS_LOG(DEBUG, "0x%02x ", u8); 35 | } 36 | } 37 | 38 | void 39 | ble_hs_log_flat_buf(const void *data, int len) 40 | { 41 | const uint8_t *u8ptr; 42 | int i; 43 | 44 | u8ptr = data; 45 | for (i = 0; i < len; i++) { 46 | BLE_HS_LOG(DEBUG, "0x%02x ", u8ptr[i]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_mbuf_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_MBUF_PRIV_ 21 | #define H_BLE_HS_MBUF_PRIV_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | struct os_mbuf; 28 | 29 | struct os_mbuf *ble_hs_mbuf_bare_pkt(void); 30 | struct os_mbuf *ble_hs_mbuf_acl_pkt(void); 31 | struct os_mbuf *ble_hs_mbuf_l2cap_pkt(void); 32 | int ble_hs_mbuf_pullup_base(struct os_mbuf **om, int base_len); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_mqueue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "ble_hs_priv.h" 21 | 22 | int 23 | ble_mqueue_init(struct ble_mqueue *mq, ble_npl_event_fn *ev_fn, void *ev_arg) 24 | { 25 | STAILQ_INIT(&mq->head); 26 | 27 | ble_npl_event_init(&mq->ev, ev_fn, ev_arg); 28 | 29 | return (0); 30 | } 31 | 32 | void 33 | ble_mqueue_deinit(struct ble_mqueue *mq) 34 | { 35 | ble_npl_event_deinit(&mq->ev); 36 | } 37 | 38 | struct os_mbuf * 39 | ble_mqueue_get(struct ble_mqueue *mq) 40 | { 41 | struct os_mbuf_pkthdr *mp; 42 | struct os_mbuf *om; 43 | os_sr_t sr; 44 | 45 | OS_ENTER_CRITICAL(sr); 46 | mp = STAILQ_FIRST(&mq->head); 47 | if (mp) { 48 | STAILQ_REMOVE_HEAD(&mq->head, omp_next); 49 | } 50 | OS_EXIT_CRITICAL(sr); 51 | 52 | if (mp) { 53 | om = OS_MBUF_PKTHDR_TO_MBUF(mp); 54 | } else { 55 | om = NULL; 56 | } 57 | 58 | return (om); 59 | } 60 | 61 | int 62 | ble_mqueue_put(struct ble_mqueue *mq, struct ble_npl_eventq *evq, struct os_mbuf *om) 63 | { 64 | struct os_mbuf_pkthdr *mp; 65 | os_sr_t sr; 66 | int rc; 67 | 68 | /* Can only place the head of a chained mbuf on the queue. */ 69 | if (!OS_MBUF_IS_PKTHDR(om)) { 70 | rc = OS_EINVAL; 71 | goto err; 72 | } 73 | 74 | mp = OS_MBUF_PKTHDR(om); 75 | 76 | OS_ENTER_CRITICAL(sr); 77 | STAILQ_INSERT_TAIL(&mq->head, mp, omp_next); 78 | OS_EXIT_CRITICAL(sr); 79 | 80 | /* Only post an event to the queue if its specified */ 81 | if (evq) { 82 | ble_npl_eventq_put(evq, &mq->ev); 83 | } 84 | 85 | return (0); 86 | err: 87 | return (rc); 88 | } 89 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_periodic_sync_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_PERIODIC_SYNC_ 21 | #define H_BLE_HS_PERIODIC_SYNC_ 22 | 23 | #include 24 | #include "nimble/porting/nimble/include/os/queue.h" 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | struct ble_hs_periodic_sync { 30 | SLIST_ENTRY(ble_hs_periodic_sync) next; 31 | uint16_t sync_handle; 32 | ble_addr_t advertiser_addr; 33 | uint8_t adv_sid; 34 | 35 | ble_gap_event_fn *cb; 36 | void *cb_arg; 37 | 38 | struct ble_npl_event lost_ev; 39 | }; 40 | 41 | struct ble_hs_periodic_sync *ble_hs_periodic_sync_alloc(void); 42 | void ble_hs_periodic_sync_free(struct ble_hs_periodic_sync *psync); 43 | void ble_hs_periodic_sync_insert(struct ble_hs_periodic_sync *psync); 44 | void ble_hs_periodic_sync_remove(struct ble_hs_periodic_sync *psync); 45 | struct ble_hs_periodic_sync *ble_hs_periodic_sync_find_by_handle(uint16_t sync_handle); 46 | struct ble_hs_periodic_sync *ble_hs_periodic_sync_find(const ble_addr_t *addr, 47 | uint8_t sid); 48 | struct ble_hs_periodic_sync *ble_hs_periodic_sync_first(void); 49 | int ble_hs_periodic_sync_init(void); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_pvcy_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_PVCY_PRIV_ 21 | #define H_BLE_HS_PVCY_PRIV_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern uint8_t ble_hs_pvcy_default_irk[16]; 30 | 31 | void ble_hs_pvcy_set_default_irk(void); 32 | int ble_hs_pvcy_set_our_irk(const uint8_t *irk); 33 | int ble_hs_pvcy_our_irk(const uint8_t **out_irk); 34 | int ble_hs_pvcy_remove_entry(uint8_t addr_type, const uint8_t *addr); 35 | int ble_hs_pvcy_add_entry(const uint8_t *addr, uint8_t addrtype, 36 | const uint8_t *irk); 37 | int ble_hs_pvcy_ensure_started(void); 38 | int ble_hs_pvcy_set_mode(const ble_addr_t *addr, uint8_t priv_mode); 39 | #if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY) 40 | bool ble_hs_pvcy_enabled(void); 41 | #endif 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_shutdown.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifdef MYNEWT 21 | 22 | #include "os/mynewt.h" 23 | #include "ble_hs_priv.h" 24 | 25 | static struct ble_hs_stop_listener ble_hs_shutdown_stop_listener; 26 | 27 | /** 28 | * Called when the host stop procedure has completed. 29 | */ 30 | static void 31 | ble_hs_shutdown_stop_cb(int status, void *arg) 32 | { 33 | SYSDOWN_ASSERT_ACTIVE(); 34 | 35 | /* Indicate to sysdown that the host is fully shut down. */ 36 | sysdown_release(); 37 | } 38 | 39 | int 40 | ble_hs_shutdown(int reason) 41 | { 42 | int rc; 43 | 44 | /* Ensure this function only gets called by sysdown. */ 45 | SYSDOWN_ASSERT_ACTIVE(); 46 | 47 | /* Initiate a host stop procedure. */ 48 | rc = ble_hs_stop(&ble_hs_shutdown_stop_listener, ble_hs_shutdown_stop_cb, 49 | NULL); 50 | switch (rc) { 51 | case 0: 52 | /* Stop initiated. Wait for result to be reported asynchronously. */ 53 | return SYSDOWN_IN_PROGRESS; 54 | 55 | case BLE_HS_EBUSY: 56 | /* Already stopping. Wait for result to be reported asynchronously. */ 57 | return SYSDOWN_IN_PROGRESS; 58 | 59 | case BLE_HS_EALREADY: 60 | /* Already stopped. Shutdown complete. */ 61 | return SYSDOWN_COMPLETE; 62 | 63 | default: 64 | BLE_HS_LOG(ERROR, "ble_hs_shutdown: failed to stop host; rc=%d\n", rc); 65 | return SYSDOWN_COMPLETE; 66 | } 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_hs_startup_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_HS_STARTUP_ 21 | #define H_BLE_HS_STARTUP_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int ble_hs_startup_go(void); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_sm_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include "nimble/nimble/include/nimble/ble.h" 23 | #include "nimble/nimble/include/nimble/nimble_opt.h" 24 | #include "nimble/nimble/host/include/host/ble_sm.h" 25 | #include "ble_hs_priv.h" 26 | 27 | #if NIMBLE_BLE_CONNECT 28 | void * 29 | ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom) 30 | { 31 | struct ble_sm_hdr *hdr; 32 | void *data; 33 | 34 | *txom = ble_hs_mbuf_l2cap_pkt(); 35 | if (*txom == NULL) { 36 | return NULL; 37 | } 38 | 39 | data = os_mbuf_extend(*txom, sizeof(*hdr) + len); 40 | if (data == NULL) { 41 | os_mbuf_free_chain(*txom); 42 | return NULL; 43 | } 44 | 45 | hdr = (struct ble_sm_hdr *)data; 46 | 47 | hdr->opcode = opcode; 48 | 49 | return hdr->data; 50 | } 51 | 52 | /* this function consumes tx os_mbuf */ 53 | int 54 | ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom) 55 | { 56 | struct ble_l2cap_chan *chan; 57 | struct ble_hs_conn *conn; 58 | int rc; 59 | 60 | BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task()); 61 | 62 | STATS_INC(ble_l2cap_stats, sm_tx); 63 | 64 | rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SM, 65 | &conn, &chan); 66 | if (rc == 0) { 67 | rc = ble_l2cap_tx(conn, chan, txom); 68 | } else { 69 | os_mbuf_free_chain(txom); 70 | } 71 | 72 | return rc; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/src/ble_uuid_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_UUID_PRIV_ 21 | #define H_BLE_UUID_PRIV_ 22 | 23 | #include "nimble/nimble/host/include/host/ble_uuid.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | struct os_mbuf; 30 | 31 | int ble_uuid_init_from_att_mbuf(ble_uuid_any_t *uuid, struct os_mbuf *om, 32 | int off, int len); 33 | int ble_uuid_init_from_att_buf(ble_uuid_any_t *uuid, const void *buf, 34 | size_t len); 35 | 36 | int ble_uuid_to_any(const ble_uuid_t *uuid, ble_uuid_any_t *uuid_any); 37 | int ble_uuid_to_mbuf(const ble_uuid_t *uuid, struct os_mbuf *om); 38 | int ble_uuid_flat(const ble_uuid_t *uuid, void *dst); 39 | int ble_uuid_length(const ble_uuid_t *uuid); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/store/config/include/store/config/ble_store_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_STORE_CONFIG_ 21 | #define H_BLE_STORE_CONFIG_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | union ble_store_key; 28 | union ble_store_value; 29 | 30 | int ble_store_config_read(int obj_type, const union ble_store_key *key, 31 | union ble_store_value *value); 32 | int ble_store_config_write(int obj_type, const union ble_store_value *val); 33 | int ble_store_config_delete(int obj_type, const union ble_store_key *key); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/store/ram/include/store/ram/ble_store_ram.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /* This package has been deprecated and you should 21 | * use the store/config package. For a RAM-only BLE store, 22 | * use store/config and set BLE_STORE_CONFIG_PERSIST to 0. 23 | */ 24 | 25 | #ifndef H_BLE_STORE_RAM_ 26 | #define H_BLE_STORE_RAM_ 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | union ble_store_key; 33 | union ble_store_value; 34 | 35 | int ble_store_ram_read(int obj_type, const union ble_store_key *key, 36 | union ble_store_value *value); 37 | int ble_store_ram_write(int obj_type, const union ble_store_value *val); 38 | int ble_store_ram_delete(int obj_type, const union ble_store_key *key); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/nimble/nimble/host/util/include/host/util/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_HOST_UTIL_ 21 | #define H_HOST_UTIL_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * Tries to configure the device with at least one Bluetooth address. 29 | * Addresses are restored in a hardware-specific fashion. 30 | * 31 | * @param prefer_random Whether to attempt to restore a random address 32 | * before checking if a public address has 33 | * already been configured. 34 | * 35 | * @return 0 on success; 36 | * BLE_HS_ENOADDR if the device does not have any 37 | * available addresses. 38 | * Other BLE host core code on error. 39 | */ 40 | int ble_hs_util_ensure_addr(int prefer_random); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/nimble/nimble/include/nimble/nimble_opt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_NIMBLE_OPT_ 21 | #define H_NIMBLE_OPT_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Include automatically-generated settings. */ 28 | #include "nimble/nimble/include/nimble/nimble_opt_auto.h" 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/nimble/nimble/transport/common/hci_h4/include/nimble/transport/hci_h4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _HCI_H4_H_ 21 | #define _HCI_H4_H_ 22 | 23 | #include 24 | 25 | #define HCI_H4_NONE 0x00 26 | #define HCI_H4_CMD 0x01 27 | #define HCI_H4_ACL 0x02 28 | #define HCI_H4_EVT 0x04 29 | #define HCI_H4_ISO 0x05 30 | 31 | typedef void *(hci_h4_alloc_cmd)(void); 32 | typedef void *(hci_h4_alloc_evt)(int); 33 | typedef struct os_mbuf *(hci_h4_alloc_acl)(void); 34 | typedef struct os_mbuf *(hci_h4_alloc_iso)(void); 35 | 36 | struct hci_h4_allocators { 37 | hci_h4_alloc_cmd *cmd; 38 | hci_h4_alloc_acl *acl; 39 | hci_h4_alloc_evt *evt; 40 | hci_h4_alloc_iso *iso; 41 | }; 42 | 43 | extern const struct hci_h4_allocators hci_h4_allocs_from_ll; 44 | extern const struct hci_h4_allocators hci_h4_allocs_from_hs; 45 | 46 | typedef int (hci_h4_frame_cb)(uint8_t pkt_type, void *data); 47 | 48 | struct hci_h4_sm { 49 | uint8_t state; 50 | uint8_t pkt_type; 51 | uint8_t min_len; 52 | uint16_t len; 53 | uint16_t exp_len; 54 | uint8_t hdr[4]; 55 | union { 56 | uint8_t *buf; 57 | struct os_mbuf *om; 58 | }; 59 | 60 | const struct hci_h4_allocators *allocs; 61 | hci_h4_frame_cb *frame_cb; 62 | }; 63 | 64 | void hci_h4_sm_init(struct hci_h4_sm *h4sm, 65 | const struct hci_h4_allocators *allocs, 66 | hci_h4_frame_cb *frame_cb); 67 | 68 | int hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len); 69 | 70 | #endif /* _HCI_H4_H_ */ 71 | -------------------------------------------------------------------------------- /src/nimble/nimble/transport/esp_ipc/src/hci_esp_ipc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | #ifdef ESP_PLATFORM 9 | #if !defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "nimble/porting/nimble/include/os/os_mbuf.h" 17 | #include "nimble/nimble/transport/include/nimble/transport.h" 18 | #include "nimble/esp_port/port/transport/include/esp_hci_transport.h" 19 | #include "nimble/esp_port/port/transport/include/esp_hci_internal.h" 20 | 21 | static int 22 | ble_transport_dummy_host_recv_cb(hci_trans_pkt_ind_t type, uint8_t *data, uint16_t len) 23 | { 24 | /* Dummy function */ 25 | return 0; 26 | } 27 | 28 | static int 29 | ble_transport_host_recv_cb(hci_trans_pkt_ind_t type, uint8_t *data, uint16_t len) 30 | { 31 | int rc; 32 | 33 | if (type == HCI_ACL_IND) { 34 | rc = ble_transport_to_hs_acl((struct os_mbuf *)data); 35 | } else { 36 | rc = ble_transport_to_hs_evt(data); 37 | } 38 | return rc; 39 | } 40 | 41 | int 42 | ble_transport_to_ll_cmd_impl(void *buf) 43 | { 44 | return na_hci_transport_host_cmd_tx(buf, 0); 45 | } 46 | 47 | int 48 | ble_transport_to_ll_acl_impl(struct os_mbuf *om) 49 | { 50 | return na_hci_transport_host_acl_tx((uint8_t *)om, 0); 51 | } 52 | 53 | void 54 | ble_transport_ll_init(void) 55 | { 56 | na_hci_transport_host_callback_register(ble_transport_host_recv_cb); 57 | } 58 | 59 | void 60 | ble_transport_ll_deinit(void) 61 | { 62 | na_hci_transport_host_callback_register(ble_transport_dummy_host_recv_cb); 63 | } 64 | 65 | void * 66 | ble_transport_alloc_cmd(void) 67 | { 68 | return r_ble_hci_trans_buf_alloc(ESP_HCI_INTERNAL_BUF_CMD); 69 | } 70 | 71 | void 72 | ble_transport_free(void *buf) 73 | { 74 | r_ble_hci_trans_buf_free(buf); 75 | } 76 | 77 | #endif /* !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32S3 */ 78 | #endif /* ESP_PLATFORM */ -------------------------------------------------------------------------------- /src/nimble/nimble/transport/esp_ipc_legacy/src/hci_esp_ipc_legacy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | #if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "nimble/nimble/transport/include/nimble/transport.h" 15 | #include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h" 16 | 17 | /* This file is only used by ESP32, ESP32C3 and ESP32S3. */ 18 | int 19 | ble_transport_to_ll_cmd_impl(void *buf) 20 | { 21 | return ble_hci_trans_hs_cmd_tx(buf); 22 | } 23 | 24 | int 25 | ble_transport_to_ll_acl_impl(struct os_mbuf *om) 26 | { 27 | return ble_hci_trans_hs_acl_tx(om); 28 | } 29 | 30 | void 31 | ble_transport_ll_init(void) 32 | { 33 | 34 | } 35 | 36 | void 37 | ble_transport_ll_deinit(void) 38 | { 39 | 40 | } 41 | 42 | #endif /* CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 */ 43 | -------------------------------------------------------------------------------- /src/nimble/nimble/transport/include/nimble/transport/monitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLE_MONITOR_ 21 | #define H_BLE_MONITOR_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define BLE_MONITOR (MYNEWT_VAL(BLE_MONITOR_RTT) || \ 30 | MYNEWT_VAL(BLE_MONITOR_UART)) 31 | 32 | #if BLE_MONITOR 33 | int ble_monitor_out(int c); 34 | int ble_monitor_log(int level, const char *fmt, ...); 35 | #else 36 | static inline int 37 | ble_monitor_out(int c) 38 | { 39 | (void)c; 40 | return 0; 41 | } 42 | static inline int 43 | ble_monitor_log(int level, const char *fmt, ...) 44 | { 45 | (void)level; 46 | (void)fmt; 47 | return 0; 48 | } 49 | 50 | static inline int 51 | ble_transport_to_ll_cmd(void *buf) 52 | { 53 | return ble_transport_to_ll_cmd_impl(buf); 54 | } 55 | 56 | static inline int 57 | ble_transport_to_ll_acl(struct os_mbuf *om) 58 | { 59 | return ble_transport_to_ll_acl_impl(om); 60 | } 61 | 62 | static inline int 63 | ble_transport_to_ll_iso(struct os_mbuf *om) 64 | { 65 | return ble_transport_to_ll_iso_impl(om); 66 | } 67 | 68 | static inline int 69 | ble_transport_to_hs_evt(void *buf) 70 | { 71 | return ble_transport_to_hs_evt_impl(buf); 72 | } 73 | 74 | static inline int 75 | ble_transport_to_hs_acl(struct os_mbuf *om) 76 | { 77 | return ble_transport_to_hs_acl_impl(om); 78 | } 79 | 80 | static inline int 81 | ble_transport_to_hs_iso(struct os_mbuf *om) 82 | { 83 | return ble_transport_to_hs_iso_impl(om); 84 | } 85 | #endif /* BLE_MONITOR */ 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/nimble/nimble/transport/include/nimble/transport/transport_ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_NIMBLE_TRANSPORT_IPC_ 21 | #define H_NIMBLE_TRANSPORT_IPC_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | 30 | /* NOTE: These APIs shall only be used by IPC transports */ 31 | 32 | #define BLE_TRANSPORT_IPC \ 33 | MYNEWT_PKG_apache_mynewt_nimble__nimble_transport_common_hci_ipc 34 | #define BLE_TRANSPORT_IPC_ON_HS \ 35 | (BLE_TRANSPORT_IPC && !MYNEWT_VAL(BLE_CONTROLLER)) 36 | #define BLE_TRANSPORT_IPC_ON_LL \ 37 | (BLE_TRANSPORT_IPC && MYNEWT_VAL(BLE_CONTROLLER)) 38 | 39 | /* Free cmd/evt buffer sent over IPC */ 40 | void ble_transport_ipc_free(void *buf); 41 | 42 | /* Get IPC type for cmd/evt buffer */ 43 | uint8_t ble_transport_ipc_buf_evt_type_get(void *buf); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* H_NIMBLE_TRANSPORT_IPC_ */ 50 | -------------------------------------------------------------------------------- /src/nimble/nimble/transport/include/nimble/transport_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_NIMBLE_TRANSPORT_IMPL_ 21 | #define H_NIMBLE_TRANSPORT_IMPL_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include "nimble/porting/nimble/include/os/os_mempool.h" 28 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 29 | 30 | /* Init functions to be implemented for transport acting as HS/LL side */ 31 | extern void ble_transport_ll_init(void); 32 | extern void ble_transport_hs_init(void); 33 | 34 | extern void ble_transport_ll_deinit(void); 35 | 36 | /* APIs to be implemented by HS/LL side of transports */ 37 | extern int ble_transport_to_ll_cmd_impl(void *buf); 38 | extern int ble_transport_to_ll_acl_impl(struct os_mbuf *om); 39 | extern int ble_transport_to_ll_iso_impl(struct os_mbuf *om); 40 | extern int ble_transport_to_hs_evt_impl(void *buf); 41 | extern int ble_transport_to_hs_acl_impl(struct os_mbuf *om); 42 | extern int ble_transport_to_hs_iso_impl(struct os_mbuf *om); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* H_NIMBLE_TRANSPORT_IMPL_ */ 49 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/hal/hal_os_tick.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @addtogroup HAL 9 | * @{ 10 | * @defgroup HALOsTick HAL OS Tick 11 | * @{ 12 | */ 13 | 14 | #ifndef H_HAL_OS_TICK_ 15 | #define H_HAL_OS_TICK_ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include "nimble/porting/nimble/include/os/os.h" 22 | 23 | typedef long os_time_t; 24 | 25 | void hal_rtc_intr_init(void); 26 | 27 | /** 28 | * Set up the periodic timer to interrupt at a frequency of 'os_ticks_per_sec'. 29 | * 'prio' is the cpu-specific priority of the periodic timer interrupt. 30 | * 31 | * @param os_ticks_per_sec Frequency of the OS tick timer 32 | * @param prio Priority of the OS tick timer 33 | */ 34 | void bleonly_os_tick_init(uint32_t os_ticks_per_sec); 35 | 36 | /** 37 | * Halt CPU for up to 'n' ticks. 38 | * 39 | * @param n The number of ticks to halt the CPU for 40 | */ 41 | void os_tick_idle(os_time_t n); 42 | 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* H_HAL_OS_TICK_ */ 49 | 50 | /** 51 | * @} HALOsTick 52 | * @} HAL 53 | */ 54 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/hal/hal_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @addtogroup HAL 9 | * @{ 10 | * @defgroup HALSystem HAL System 11 | * @{ 12 | */ 13 | 14 | #ifndef H_HAL_SYSTEM_ 15 | #define H_HAL_SYSTEM_ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /** 22 | * System reset. 23 | */ 24 | void hal_system_reset(void) __attribute((noreturn)); 25 | 26 | /** 27 | * Called by bootloader to start loaded program. 28 | */ 29 | void hal_system_start(void *img_start) __attribute((noreturn)); 30 | 31 | /** 32 | * Called by split app loader to start the app program. 33 | */ 34 | void hal_system_restart(void *img_start) __attribute((noreturn)); 35 | 36 | /** 37 | * Returns non-zero if there is a HW debugger attached. 38 | */ 39 | int hal_debugger_connected(void); 40 | 41 | /** 42 | * Reboot reason 43 | */ 44 | enum hal_reset_reason { 45 | /** Power on Reset */ 46 | HAL_RESET_POR = 1, 47 | /** Caused by Reset Pin */ 48 | HAL_RESET_PIN = 2, 49 | /** Caused by Watchdog */ 50 | HAL_RESET_WATCHDOG = 3, 51 | /** Soft reset, either system reset or crash */ 52 | HAL_RESET_SOFT = 4, 53 | /** Low supply voltage */ 54 | HAL_RESET_BROWNOUT = 5, 55 | /** Restart due to user request */ 56 | HAL_RESET_REQUESTED = 6, 57 | /** System Off, wakeup on external interrupt*/ 58 | HAL_RESET_SYS_OFF_INT = 7, 59 | /** Restart due to DFU */ 60 | HAL_RESET_DFU = 8, 61 | }; 62 | 63 | /** 64 | * Return the reboot reason 65 | * 66 | * @return A reboot reason 67 | */ 68 | enum hal_reset_reason hal_reset_cause(void); 69 | 70 | /** 71 | * Return the reboot reason as a string 72 | * 73 | * @return String describing previous reset reason 74 | */ 75 | const char *hal_reset_cause_str(void); 76 | 77 | /** 78 | * Starts clocks needed by system 79 | */ 80 | void hal_system_clock_start(void); 81 | 82 | /** 83 | * Reset callback to be called before an reset happens inside hal_system_reset() 84 | */ 85 | void hal_system_reset_cb(void); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /* H_HAL_SYSTEM_ */ 92 | 93 | /** 94 | * @} HALSystem 95 | * @} HAL 96 | */ 97 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/hal/hal_watchdog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @addtogroup HAL 9 | * @{ 10 | * @defgroup HALWatchdog HAL Watchdog 11 | * @{ 12 | */ 13 | 14 | #ifndef _HAL_WATCHDOG_H_ 15 | #define _HAL_WATCHDOG_H_ 16 | 17 | #include 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * Set a recurring watchdog timer to fire no sooner than in 'expire_secs' 24 | * seconds. Watchdog should be tickled periodically with a frequency 25 | * smaller than 'expire_secs'. Watchdog needs to be then started with 26 | * a call to :c:func:`hal_watchdog_enable()`. 27 | * 28 | * @param expire_msecs Watchdog timer expiration time in msecs 29 | * 30 | * @return < 0 on failure; on success return the actual 31 | * expiration time as positive value 32 | */ 33 | int hal_watchdog_init(uint32_t expire_msecs); 34 | 35 | /** 36 | * Starts the watchdog. 37 | */ 38 | void hal_watchdog_enable(void); 39 | 40 | /** 41 | * Tickles the watchdog. This needs to be done periodically, before 42 | * the value configured in :c:func:`hal_watchdog_init()` expires. 43 | */ 44 | void hal_watchdog_tickle(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _HAL_WATCHDOG_H_ */ 51 | 52 | /** 53 | * @} HALWatchdog 54 | * @} HAL 55 | */ 56 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/log/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef __LOG_H__ 21 | #define __LOG_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | struct log { 28 | }; 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* __LOG_H__ */ 35 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/log_common/ignore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_IGNORE_ 21 | #define H_IGNORE_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * These macros prevent the "set but not used" warnings for log writes below 29 | * the log level. 30 | */ 31 | 32 | #define IGN_1(X) ((void)(X)) 33 | #define IGN_2(X, ...) ((void)(X));IGN_1(__VA_ARGS__) 34 | #define IGN_3(X, ...) ((void)(X));IGN_2(__VA_ARGS__) 35 | #define IGN_4(X, ...) ((void)(X));IGN_3(__VA_ARGS__) 36 | #define IGN_5(X, ...) ((void)(X));IGN_4(__VA_ARGS__) 37 | #define IGN_6(X, ...) ((void)(X));IGN_5(__VA_ARGS__) 38 | #define IGN_7(X, ...) ((void)(X));IGN_6(__VA_ARGS__) 39 | #define IGN_8(X, ...) ((void)(X));IGN_7(__VA_ARGS__) 40 | #define IGN_9(X, ...) ((void)(X));IGN_8(__VA_ARGS__) 41 | #define IGN_10(X, ...) ((void)(X));IGN_9(__VA_ARGS__) 42 | #define IGN_11(X, ...) ((void)(X));IGN_10(__VA_ARGS__) 43 | #define IGN_12(X, ...) ((void)(X));IGN_11(__VA_ARGS__) 44 | #define IGN_13(X, ...) ((void)(X));IGN_12(__VA_ARGS__) 45 | #define IGN_14(X, ...) ((void)(X));IGN_13(__VA_ARGS__) 46 | #define IGN_15(X, ...) ((void)(X));IGN_14(__VA_ARGS__) 47 | #define IGN_16(X, ...) ((void)(X));IGN_15(__VA_ARGS__) 48 | #define IGN_17(X, ...) ((void)(X));IGN_16(__VA_ARGS__) 49 | #define IGN_18(X, ...) ((void)(X));IGN_17(__VA_ARGS__) 50 | #define IGN_19(X, ...) ((void)(X));IGN_18(__VA_ARGS__) 51 | #define IGN_20(X, ...) ((void)(X));IGN_19(__VA_ARGS__) 52 | 53 | #define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \ 54 | _13, _14, _15, _16, _17, _18, _19, _20, NAME, ...) NAME 55 | #define IGNORE(...) \ 56 | GET_MACRO(__VA_ARGS__, IGN_20, IGN_19, IGN_18, IGN_17, IGN_16, IGN_15, \ 57 | IGN_14, IGN_13, IGN_12, IGN_11, IGN_10, IGN_9, IGN_8, IGN_7, \ 58 | IGN_6, IGN_5, IGN_4, IGN_3, IGN_2, IGN_1)(__VA_ARGS__) 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/nimble/storage_port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _STORAGE_PORT_H 21 | #define _STORAGE_PORT_H 22 | 23 | #include 24 | 25 | typedef enum { 26 | READONLY, 27 | READWRITE 28 | } open_mode_t; 29 | 30 | typedef uint32_t cache_handle_t; 31 | typedef int (*open_cache)(const char *namespace_name, open_mode_t open_mode, cache_handle_t *out_handle); 32 | typedef void (*close_cache)(cache_handle_t handle); 33 | typedef int (*erase_all_cache)(cache_handle_t handle); 34 | typedef int (*write_cache)(cache_handle_t handle, const char *key, const void* value, size_t length); 35 | typedef int (*read_cache)(cache_handle_t handle, const char *key, void* out_value, size_t *length); 36 | 37 | struct cache_fn_mapping { 38 | open_cache open; 39 | close_cache close; 40 | erase_all_cache erase_all; 41 | write_cache write; 42 | read_cache read; 43 | }; 44 | 45 | struct cache_fn_mapping link_storage_fn(void *storage_cb); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/os/os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _OS_H 21 | #define _OS_H 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #if !defined __cplusplus 30 | #define static_assert _Static_assert 31 | #endif 32 | 33 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 34 | #include "nimble/nimble/include/nimble/nimble_npl.h" 35 | 36 | #define OS_ALIGN(__n, __a) ( \ 37 | (((__n) & ((__a) - 1)) == 0) ? \ 38 | (__n) : \ 39 | ((__n) + ((__a) - ((__n) & ((__a) - 1)))) \ 40 | ) 41 | #define OS_ALIGNMENT (BLE_NPL_OS_ALIGNMENT) 42 | 43 | typedef uint32_t os_sr_t; 44 | #define OS_ENTER_CRITICAL(_sr) (_sr = ble_npl_hw_enter_critical()) 45 | #define OS_EXIT_CRITICAL(_sr) (ble_npl_hw_exit_critical(_sr)) 46 | #define OS_ASSERT_CRITICAL() assert(ble_npl_hw_is_in_critical()) 47 | 48 | /* Mynewt components (not abstracted in NPL) */ 49 | #include "nimble/porting/nimble/include/os/endian.h" 50 | #include "nimble/porting/nimble/include/os/queue.h" 51 | #include "nimble/porting/nimble/include/os/os_error.h" 52 | #include "nimble/porting/nimble/include/os/os_mbuf.h" 53 | #include "nimble/porting/nimble/include/os/os_mempool.h" 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* _OS_H */ 60 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/os/os_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_OS_ERROR_ 21 | #define H_OS_ERROR_ 22 | 23 | #include "nimble/porting/nimble/include/os/os.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* OS error enumerations */ 30 | enum os_error { 31 | OS_OK = 0, 32 | OS_ENOMEM = 1, 33 | OS_EINVAL = 2, 34 | OS_INVALID_PARM = 3, 35 | OS_MEM_NOT_ALIGNED = 4, 36 | OS_BAD_MUTEX = 5, 37 | OS_TIMEOUT = 6, 38 | OS_ERR_IN_ISR = 7, /* Function cannot be called from ISR */ 39 | OS_ERR_PRIV = 8, /* Privileged access error */ 40 | OS_NOT_STARTED = 9, /* OS must be started to call this function, but isn't */ 41 | OS_ENOENT = 10, /* No such thing */ 42 | OS_EBUSY = 11, /* Resource busy */ 43 | OS_ERROR = 12, /* Generic Error */ 44 | }; 45 | 46 | typedef enum os_error os_error_t; 47 | 48 | /** 49 | * @brief Converts an OS error code (`OS_[...]`) to an equivalent system error 50 | * code (`SYS_E[...]`). 51 | * 52 | * @param os_error The OS error code to convert. 53 | * 54 | * @return The equivalent system error code. 55 | */ 56 | int os_error_to_sys(os_error_t os_error); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/os/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_OS_UTIL_ 21 | #define H_OS_UTIL_ 22 | 23 | /* Helpers to pass integers as pointers and vice-versa */ 24 | #define POINTER_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) 25 | #define UINT_TO_POINTER(u) ((void *) ((uintptr_t) (u))) 26 | #define POINTER_TO_INT(p) ((int) ((intptr_t) (p))) 27 | #define INT_TO_POINTER(u) ((void *) ((intptr_t) (u))) 28 | 29 | /* Helper to retrieve pointer to "parent" object in structure */ 30 | #define CONTAINER_OF(ptr, type, field) \ 31 | ((type *)(((char *)(ptr)) - offsetof(type, field))) 32 | 33 | /* Helper to calculate number of elements in array */ 34 | #ifndef ARRAY_SIZE 35 | #define ARRAY_SIZE(array) \ 36 | (sizeof(array) / sizeof((array)[0])) 37 | #endif 38 | #endif 39 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/stats/stats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef __STATS_H__ 21 | #define __STATS_H__ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define STATS_SECT_DECL(__name) struct stats_ ## __name 30 | #define STATS_SECT_END }; 31 | 32 | #define STATS_SECT_START(__name) STATS_SECT_DECL(__name) { 33 | #define STATS_SECT_VAR(__var) 34 | 35 | #define STATS_HDR(__sectname) NULL 36 | 37 | #define STATS_SECT_ENTRY(__var) 38 | #define STATS_SECT_ENTRY16(__var) 39 | #define STATS_SECT_ENTRY32(__var) 40 | #define STATS_SECT_ENTRY64(__var) 41 | #define STATS_RESET(__var) 42 | 43 | #define STATS_SIZE_INIT_PARMS(__sectvarname, __size) \ 44 | 0, 0 45 | 46 | #define STATS_INC(__sectvarname, __var) 47 | #define STATS_INCN(__sectvarname, __var, __n) 48 | #define STATS_CLEAR(__sectvarname, __var) 49 | 50 | #define STATS_NAME_START(__name) 51 | #define STATS_NAME(__name, __entry) 52 | #define STATS_NAME_END(__name) 53 | #define STATS_NAME_INIT_PARMS(__name) NULL, 0 54 | 55 | static inline int 56 | stats_init(void *a, uint8_t b, uint8_t c, void *d, uint8_t e) 57 | { 58 | /* dummy */ 59 | return 0; 60 | } 61 | 62 | static inline int 63 | stats_register(void *a, void *b) 64 | { 65 | /* dummy */ 66 | return 0; 67 | } 68 | 69 | static inline int 70 | stats_init_and_reg(void *a, uint8_t b, uint8_t c, void *d, uint8_t e, const char *f) 71 | { 72 | /* dummy */ 73 | return 0; 74 | } 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __STATS_H__ */ 81 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/sysflash/sysflash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file was generated by Apache newt version: 1.11.0-dev 3 | */ 4 | 5 | #ifndef H_MYNEWT_SYSFLASH_ 6 | #define H_MYNEWT_SYSFLASH_ 7 | 8 | #include "flash_map/flash_map.h" 9 | 10 | /** 11 | * This flash map definition is used for two purposes: 12 | * 1. To locate the meta area, which contains the true flash map definition. 13 | * 2. As a fallback in case the meta area cannot be read from flash. 14 | */ 15 | extern const struct flash_area sysflash_map_dflt[6]; 16 | 17 | #define FLASH_AREA_BOOTLOADER 0 18 | #define FLASH_AREA_BOOTLOADER_DEVICE 0 19 | #define FLASH_AREA_BOOTLOADER_OFFSET 0x00000000 20 | #define FLASH_AREA_BOOTLOADER_SIZE 16384 21 | 22 | #define FLASH_AREA_IMAGE_0 1 23 | #define FLASH_AREA_IMAGE_0_DEVICE 0 24 | #define FLASH_AREA_IMAGE_0_OFFSET 0x00020000 25 | #define FLASH_AREA_IMAGE_0_SIZE 393216 26 | 27 | #define FLASH_AREA_IMAGE_1 2 28 | #define FLASH_AREA_IMAGE_1_DEVICE 0 29 | #define FLASH_AREA_IMAGE_1_OFFSET 0x00080000 30 | #define FLASH_AREA_IMAGE_1_SIZE 393216 31 | 32 | #define FLASH_AREA_IMAGE_SCRATCH 3 33 | #define FLASH_AREA_IMAGE_SCRATCH_DEVICE 0 34 | #define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x000e0000 35 | #define FLASH_AREA_IMAGE_SCRATCH_SIZE 131072 36 | 37 | #define FLASH_AREA_REBOOT_LOG 16 38 | #define FLASH_AREA_REBOOT_LOG_DEVICE 0 39 | #define FLASH_AREA_REBOOT_LOG_OFFSET 0x00004000 40 | #define FLASH_AREA_REBOOT_LOG_SIZE 16384 41 | 42 | #define FLASH_AREA_NFFS 17 43 | #define FLASH_AREA_NFFS_DEVICE 0 44 | #define FLASH_AREA_NFFS_OFFSET 0x00008000 45 | #define FLASH_AREA_NFFS_SIZE 32768 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/nimble/porting/nimble/include/sysinit/sysinit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef __SYSINIT_H__ 21 | #define __SYSINIT_H__ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define SYSINIT_ASSERT_ACTIVE() 30 | 31 | #define SYSINIT_PANIC_ASSERT(rc) assert(rc) 32 | #define SYSINIT_PANIC_ASSERT_MSG(rc, msg) assert(rc) 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* __SYSINIT_H__ */ 39 | -------------------------------------------------------------------------------- /src/nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _NIMBLE_PORT_FREERTOS_H 21 | #define _NIMBLE_PORT_FREERTOS_H 22 | 23 | #include "nimble/nimble/include/nimble/nimble_npl.h" 24 | #ifdef ESP_PLATFORM 25 | #include "esp_err.h" 26 | #endif 27 | 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef ESP_PLATFORM 34 | /** 35 | * @brief esp_nimble_enable - Initialize the NimBLE host task 36 | * 37 | * @param host_task 38 | * @return esp_err_t 39 | */ 40 | esp_err_t esp_nimble_enable(void *host_task); 41 | 42 | /** 43 | * @brief esp_nimble_disable - Disable the NimBLE host task 44 | * 45 | * @return esp_err_t 46 | */ 47 | esp_err_t esp_nimble_disable(void); 48 | #endif 49 | 50 | void nimble_port_freertos_init(TaskFunction_t host_task_fn); 51 | void nimble_port_freertos_deinit(void); 52 | void npl_freertos_funcs_init(void); 53 | void npl_freertos_funcs_deinit(void); 54 | int npl_freertos_mempool_init(void); 55 | struct npl_funcs_t * npl_freertos_funcs_get(void); 56 | #ifndef ESP_PLATFORM 57 | UBaseType_t nimble_port_freertos_get_ll_hwm(void); 58 | #endif 59 | UBaseType_t nimble_port_freertos_get_hs_hwm(void); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* _NIMBLE_PORT_FREERTOS_H */ 66 | -------------------------------------------------------------------------------- /src/syscfg/syscfg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "nimble/porting/nimble/include/syscfg/syscfg.h" 3 | --------------------------------------------------------------------------------