|
| 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_RAS_ |
| 21 | +#define H_BLE_SVC_RAS_ |
| 22 | + |
| 23 | +#include <inttypes.h> |
| 24 | +#include "host/ble_cs.h" |
| 25 | + |
| 26 | +#ifdef __cplusplus |
| 27 | +extern "C" { |
| 28 | +#endif |
| 29 | + |
| 30 | +#define BLE_CONN_HANDLE_INVALID 0xffff |
| 31 | + |
| 32 | +#define BLE_SVC_RAS_SVC_RANGING_SERVICE_UUID 0x185B |
| 33 | +#define BLE_SVC_RAS_CHR_RAS_FEATURES_UUID 0x2C14 |
| 34 | +#define BLE_SVC_RAS_CHR_REAL_TIME_RANGING_DATA_UUID 0x2C15 |
| 35 | +#define BLE_SVC_RAS_CHR_ON_DEMAND_RANGING_DATA_UUID 0x2C16 |
| 36 | +#define BLE_SVC_RAS_CHR_RAS_CONTROL_POINT_UUID 0x2C17 |
| 37 | +#define BLE_SVC_RAS_CHR_RANGING_DATA_READY_UUID 0x2C18 |
| 38 | +#define BLE_SVC_RAS_CHR_RANGING_DATA_OVERWRITTEN_UUID 0x2C19 |
| 39 | + |
| 40 | +#define BLE_SVC_RAS_FILTER_MODE0_POSITION (0) |
| 41 | +#define BLE_SVC_RAS_FILTER_MODE1_POSITION (BLE_SVC_RAS_FILTER_MODE0_POSITION << 14) |
| 42 | +#define BLE_SVC_RAS_FILTER_MODE2_POSITION (BLE_SVC_RAS_FILTER_MODE1_POSITION << 14) |
| 43 | +#define BLE_SVC_RAS_FILTER_MODE3_POSITION (BLE_SVC_RAS_FILTER_MODE3_POSITION << 14) |
| 44 | + |
| 45 | +#define BLE_SVC_RAS_FILTER_MODE0_MASK (0xF) |
| 46 | +#define BLE_SVC_RAS_FILTER_MODE1_MASK (0x7F) |
| 47 | +#define BLE_SVC_RAS_FILTER_MODE2_MASK (0x7F) |
| 48 | +#define BLE_SVC_RAS_FILTER_MODE3_MASK (0x3FFF) |
| 49 | + |
| 50 | +#define BLE_SVC_RAS_FILTER_MODE0_PACKET_QUALITY (0) |
| 51 | +#define BLE_SVC_RAS_FILTER_MODE0_PACKET_RSSI (1) |
| 52 | +#define BLE_SVC_RAS_FILTER_MODE0_PACKET_ANTENNA (2) |
| 53 | +#define BLE_SVC_RAS_FILTER_MODE0_MEASURED_FREQ_OFFSET (3) |
| 54 | + |
| 55 | +#define BLE_SVC_RAS_FILTER_MODE1_PACKET_QUALITY (0) |
| 56 | +#define BLE_SVC_RAS_FILTER_MODE1_PACKET_NADM (1) |
| 57 | +#define BLE_SVC_RAS_FILTER_MODE1_PACKET_RSSI (2) |
| 58 | +#define BLE_SVC_RAS_FILTER_MODE1_TOD_TOA (3) |
| 59 | +#define BLE_SVC_RAS_FILTER_MODE1_PACKET_ANTENNA (4) |
| 60 | +#define BLE_SVC_RAS_FILTER_MODE1_PACKET_PCT1 (5) |
| 61 | +#define BLE_SVC_RAS_FILTER_MODE1_PACKET_PCT2 (6) |
| 62 | + |
| 63 | +#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PERMUTATION_ID (0) |
| 64 | +#define BLE_SVC_RAS_FILTER_MODE2_TONE_PCT (1) |
| 65 | +#define BLE_SVC_RAS_FILTER_MODE2_TONE_QUALITY (2) |
| 66 | +#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_1 (3) |
| 67 | +#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_2 (4) |
| 68 | +#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_3 (5) |
| 69 | +#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_4 (6) |
| 70 | + |
| 71 | +#define BLE_SVC_RAS_FILTER_MODE3_PACKET_QUALITY (0) |
| 72 | +#define BLE_SVC_RAS_FILTER_MODE3_PACKET_NADM (1) |
| 73 | +#define BLE_SVC_RAS_FILTER_MODE3_PACKET_RSSI (2) |
| 74 | +#define BLE_SVC_RAS_FILTER_MODE3_TOD_TOA (3) |
| 75 | +#define BLE_SVC_RAS_FILTER_MODE3_PACKET_ANTENNA (4) |
| 76 | +#define BLE_SVC_RAS_FILTER_MODE3_PACKET_PCT1 (5) |
| 77 | +#define BLE_SVC_RAS_FILTER_MODE3_PACKET_PCT2 (6) |
| 78 | +#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PERMUTATION_ID (7) |
| 79 | +#define BLE_SVC_RAS_FILTER_MODE3_TONE_PCT (8) |
| 80 | +#define BLE_SVC_RAS_FILTER_MODE3_TONE_QUALITY (9) |
| 81 | +#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_1 (10) |
| 82 | +#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_2 (11) |
| 83 | +#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_3 (12) |
| 84 | +#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_4 (13) |
| 85 | + |
| 86 | +#define BLE_SVC_RAS_CP_CMD_GET_RANGING_DATA (0x00) |
| 87 | +#define BLE_SVC_RAS_CP_CMD_ACK_RANGING_DATA (0x01) |
| 88 | +#define BLE_SVC_RAS_CP_CMD_RETRIEVE_LOST_SEGMENT (0x02) |
| 89 | +#define BLE_SVC_RAS_CP_CMD_ABORT_OPERATION (0x03) |
| 90 | +#define BLE_SVC_RAS_CP_CMD_SET_FILTER (0x04) |
| 91 | + |
| 92 | +#define BLE_SVC_RAS_CP_RSP_COMPLETE_RANGING_DATA (0x00) |
| 93 | +#define BLE_SVC_RAS_CP_RSP_COMPLETE_LOST_SEGMENT (0x01) |
| 94 | +#define BLE_SVC_RAS_CP_RSP_RESPONSE_CODE (0x02) |
| 95 | + |
| 96 | +#define BLE_SVC_RAS_CP_RSPCODE_SUCCESS (0x01) |
| 97 | +#define BLE_SVC_RAS_CP_RSPCODE_OP_CODE_NOT_SUPPORTED (0x02) |
| 98 | +#define BLE_SVC_RAS_CP_RSPCODE_INVALID_PARAMETER (0x03) |
| 99 | +#define BLE_SVC_RAS_CP_RSPCODE_SUCCESS_PERSISTED (0x04) |
| 100 | +#define BLE_SVC_RAS_CP_RSPCODE_ABORT_UNSUCCESSFUL (0x05) |
| 101 | +#define BLE_SVC_RAS_CP_RSPCODE_PROCEDURE_NOT_COMPLETED (0x06) |
| 102 | +#define BLE_SVC_RAS_CP_RSPCODE_SERVER_BUSY (0x07) |
| 103 | +#define BLE_SVC_RAS_CP_RSPCODE_NO_RECORDS_FOUND (0x08) |
| 104 | + |
| 105 | +#define BLE_SVC_RAS_MODE_REAL_TIME (0) |
| 106 | +#define BLE_SVC_RAS_MODE_ON_DEMAND (1) |
| 107 | + |
| 108 | +#if MYNEWT_VAL(BLE_SVC_RAS_SERVER) |
| 109 | +void ble_svc_ras_init(void); |
| 110 | +int ble_svc_ras_ranging_data_body_init(uint16_t conn_handle, uint16_t procedure_counter, uint8_t config_id, |
| 111 | + uint8_t tx_power, uint8_t antenna_paths_mask); |
| 112 | +int ble_svc_ras_ranging_subevent_init(uint16_t conn_handle, uint16_t start_acl_conn_event, uint16_t frequency_compensation, |
| 113 | + uint8_t ranging_done_status, uint8_t subevent_done_status, |
| 114 | + uint8_t ranging_abort_reason, uint8_t subevent_abort_reason, |
| 115 | + uint8_t reference_power_level, uint8_t number_of_steps_reported); |
| 116 | +int ble_svc_ras_ranging_subevent_update_status(uint16_t conn_handle, uint8_t number_of_steps_reported, |
| 117 | + uint8_t ranging_done_status, uint8_t subevent_done_status, |
| 118 | + uint8_t ranging_abort_reason, uint8_t subevent_abort_reason); |
| 119 | +int ble_svc_ras_add_step_mode(uint16_t conn_handle, uint8_t mode, uint8_t status); |
| 120 | +int ble_svc_ras_add_mode0_result(struct ble_cs_mode0_result *result, uint16_t conn_handle, uint8_t local_role); |
| 121 | +int ble_svc_ras_add_mode1_result(struct ble_cs_mode1_result *result, uint16_t conn_handle, uint8_t rtt_pct_included); |
| 122 | +int ble_svc_ras_add_mode2_result(struct ble_cs_mode2_result *result, uint16_t conn_handle, uint8_t n_ap); |
| 123 | +int ble_svc_ras_add_mode3_result(struct ble_cs_mode3_result *result, uint16_t conn_handle, uint8_t n_ap, uint8_t rtt_pct_included); |
| 124 | +int ble_svc_ras_ranging_data_ready(uint16_t conn_handle); |
| 125 | +#endif |
| 126 | + |
| 127 | +#if MYNEWT_VAL(BLE_SVC_RAS_CLIENT) |
| 128 | +struct ble_svc_ras_clt_ranging_header { |
| 129 | + uint16_t ranging_counter; |
| 130 | + uint8_t config_id; |
| 131 | + uint8_t tx_power; |
| 132 | + uint8_t antenna_paths_mask; |
| 133 | +}; |
| 134 | + |
| 135 | +struct ble_svc_ras_clt_subevent_header { |
| 136 | + uint16_t start_acl_conn_event; |
| 137 | + uint16_t frequency_compensation; |
| 138 | + uint8_t done_status; |
| 139 | + uint8_t abort_reason; |
| 140 | + uint8_t reference_power_level; |
| 141 | + uint8_t number_of_steps_reported; |
| 142 | +}; |
| 143 | + |
| 144 | +typedef void ble_svc_ras_clt_subscribe_cb(uint16_t conn_handle); |
| 145 | +typedef void ble_svc_ras_clt_step_data_received_cb(void *data, uint16_t conn_handle, uint8_t step_mode); |
| 146 | +int ble_svc_ras_clt_config_set(uint16_t conn_handle, uint8_t rtt_pct_included, uint8_t n_ap, uint8_t local_role); |
| 147 | +int ble_svc_ras_clt_subscribe(ble_svc_ras_clt_subscribe_cb *subscribe_cb, |
| 148 | + ble_svc_ras_clt_step_data_received_cb *step_data_cb, |
| 149 | + uint16_t conn_handle, uint8_t mode); |
| 150 | +#endif |
| 151 | +#ifdef __cplusplus |
| 152 | +} |
| 153 | +#endif |
| 154 | + |
| 155 | +#endif |
0 commit comments