Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 66 additions & 15 deletions nimble/host/include/host/ble_cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,86 @@
#define H_BLE_CS_
#include "syscfg/syscfg.h"

#define BLE_HS_CS_MODE0 (0)
#define BLE_HS_CS_MODE1 (1)
#define BLE_HS_CS_MODE2 (2)
#define BLE_HS_CS_MODE3 (3)
#define BLE_HS_CS_MODE_UNUSED (0xff)
#define BLE_HS_CS_SUBMODE_TYPE BLE_HS_CS_MODE_UNUSED

#define BLE_HS_CS_ROLE_INITIATOR (0)
#define BLE_HS_CS_ROLE_REFLECTOR (1)

#define BLE_CS_EVENT_CS_PROCEDURE_COMPLETE (0)
#define BLE_CS_EVENT_CS_STEP_DATA (1)

#define BLE_HS_CS_TOA_TOD_NOT_AVAILABLE (0x00008000)
#define BLE_HS_CS_N_AP_MAX (4)

struct ble_cs_mode0_result {
uint16_t measured_freq_offset;
uint8_t packet_quality;
uint8_t packet_rssi;
uint8_t packet_antenna;
};

struct ble_cs_mode1_result {
uint32_t packet_pct1;
uint32_t packet_pct2;
int16_t toa_tod;
uint8_t packet_quality;
uint8_t packet_nadm;
uint8_t packet_rssi;
uint8_t packet_antenna;
};

struct ble_cs_mode2_result {
uint32_t tone_pct[BLE_HS_CS_N_AP_MAX + 1];
uint8_t tone_quality_ind[BLE_HS_CS_N_AP_MAX + 1];
uint8_t antenna_paths[4];
uint8_t antenna_path_permutation_id;
};

struct ble_cs_mode3_result {
uint32_t packet_pct1;
uint32_t packet_pct2;
uint32_t tone_pct[BLE_HS_CS_N_AP_MAX + 1];
uint8_t tone_quality_ind[BLE_HS_CS_N_AP_MAX + 1];
uint8_t antenna_paths[4];
int16_t toa_tod;
uint8_t antenna_path_permutation_id;
uint8_t packet_quality;
uint8_t packet_nadm;
uint8_t packet_rssi;
uint8_t packet_antenna;
};

struct ble_cs_event {
uint16_t conn_handle;
uint8_t status;
uint8_t type;
union
{
struct
{
uint16_t conn_handle;
uint8_t status;
} procedure_complete;
union {
struct {
uint8_t role;
uint8_t mode;
uint8_t *data;
} step_data;
};

};

typedef int ble_cs_event_fn(struct ble_cs_event *event, void *arg);

struct ble_cs_initiator_procedure_start_params {
struct ble_cs_procedure_start_params {
uint16_t conn_handle;
ble_cs_event_fn *cb;
void *cb_arg;
};

struct ble_cs_reflector_setup_params {
struct ble_cs_setup_params {
uint16_t conn_handle;
ble_cs_event_fn *cb;
void *cb_arg;
};

int ble_cs_initiator_procedure_start(const struct ble_cs_initiator_procedure_start_params *params);
int ble_cs_initiator_procedure_terminate(uint16_t conn_handle);
int ble_cs_reflector_setup(struct ble_cs_reflector_setup_params *params);
int ble_cs_procedure_start(const struct ble_cs_procedure_start_params *params);
int ble_cs_procedure_terminate(uint16_t conn_handle);
int ble_cs_setup(struct ble_cs_setup_params *params);
#endif
85 changes: 85 additions & 0 deletions nimble/host/include/host/ble_peer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef H_BLE_PEER_
#define H_BLE_PEER_

#include "os/mynewt.h"
#ifdef __cplusplus
extern "C" {
#endif

/** Peer. */
struct ble_peer_dsc {
SLIST_ENTRY(ble_peer_dsc) next;
struct ble_gatt_dsc dsc;
};
SLIST_HEAD(ble_peer_dsc_list, ble_peer_dsc);

struct ble_peer_chr {
SLIST_ENTRY(ble_peer_chr) next;
struct ble_gatt_chr chr;

struct ble_peer_dsc_list dscs;
};
SLIST_HEAD(ble_peer_chr_list, ble_peer_chr);

struct ble_peer_svc {
SLIST_ENTRY(ble_peer_svc) next;
struct ble_gatt_svc svc;

struct ble_peer_chr_list chrs;
};
SLIST_HEAD(ble_peer_svc_list, ble_peer_svc);

struct ble_peer;
typedef void ble_peer_disc_fn(const struct ble_peer *peer, int status, void *arg);

struct ble_peer {
SLIST_ENTRY(ble_peer) next;

uint16_t conn_handle;

/** List of discovered GATT services. */
struct ble_peer_svc_list svcs;

/** Keeps track of where we are in the service discovery process. */
uint16_t disc_prev_chr_val;
struct ble_peer_svc *cur_svc;

/** Callback that gets executed when service discovery completes. */
ble_peer_disc_fn *disc_cb;
void *disc_cb_arg;
};

struct ble_peer *ble_peer_find(uint16_t conn_handle);
int ble_peer_disc_all(uint16_t conn_handle, ble_peer_disc_fn *disc_cb, void *disc_cb_arg);
const struct ble_peer_dsc *ble_peer_dsc_find_uuid(const struct ble_peer *peer,
const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
const struct ble_peer_chr *ble_peer_chr_find_uuid(const struct ble_peer *peer,
const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid);
const struct ble_peer_svc *ble_peer_svc_find_uuid(const struct ble_peer *peer, const ble_uuid_t *uuid);
int ble_peer_delete(uint16_t conn_handle);
int ble_peer_add(uint16_t conn_handle);

#ifdef __cplusplus
}
#endif

#endif
6 changes: 6 additions & 0 deletions nimble/host/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ pkg.req_apis:

pkg.down.BLE_HS_STOP_ON_SHUTDOWN:
ble_hs_shutdown: 200

pkg.init.'BLE_PEER':
ble_peer_init: $after:ble_transport_hs_init

pkg.init.'BLE_CHANNEL_SOUNDING':
ble_cs_init: $after:ble_transport_hs_init
155 changes: 155 additions & 0 deletions nimble/host/services/ras/include/services/ras/ble_svc_ras.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef H_BLE_SVC_RAS_
#define H_BLE_SVC_RAS_

#include <inttypes.h>
#include "host/ble_cs.h"

#ifdef __cplusplus
extern "C" {
#endif

#define BLE_CONN_HANDLE_INVALID 0xffff

#define BLE_SVC_RAS_SVC_RANGING_SERVICE_UUID 0x185B
#define BLE_SVC_RAS_CHR_RAS_FEATURES_UUID 0x2C14
#define BLE_SVC_RAS_CHR_REAL_TIME_RANGING_DATA_UUID 0x2C15
#define BLE_SVC_RAS_CHR_ON_DEMAND_RANGING_DATA_UUID 0x2C16
#define BLE_SVC_RAS_CHR_RAS_CONTROL_POINT_UUID 0x2C17
#define BLE_SVC_RAS_CHR_RANGING_DATA_READY_UUID 0x2C18
#define BLE_SVC_RAS_CHR_RANGING_DATA_OVERWRITTEN_UUID 0x2C19

#define BLE_SVC_RAS_FILTER_MODE0_POSITION (0)
#define BLE_SVC_RAS_FILTER_MODE1_POSITION (BLE_SVC_RAS_FILTER_MODE0_POSITION << 14)
#define BLE_SVC_RAS_FILTER_MODE2_POSITION (BLE_SVC_RAS_FILTER_MODE1_POSITION << 14)
#define BLE_SVC_RAS_FILTER_MODE3_POSITION (BLE_SVC_RAS_FILTER_MODE3_POSITION << 14)

#define BLE_SVC_RAS_FILTER_MODE0_MASK (0xF)
#define BLE_SVC_RAS_FILTER_MODE1_MASK (0x7F)
#define BLE_SVC_RAS_FILTER_MODE2_MASK (0x7F)
#define BLE_SVC_RAS_FILTER_MODE3_MASK (0x3FFF)

#define BLE_SVC_RAS_FILTER_MODE0_PACKET_QUALITY (0)
#define BLE_SVC_RAS_FILTER_MODE0_PACKET_RSSI (1)
#define BLE_SVC_RAS_FILTER_MODE0_PACKET_ANTENNA (2)
#define BLE_SVC_RAS_FILTER_MODE0_MEASURED_FREQ_OFFSET (3)

#define BLE_SVC_RAS_FILTER_MODE1_PACKET_QUALITY (0)
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_NADM (1)
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_RSSI (2)
#define BLE_SVC_RAS_FILTER_MODE1_TOD_TOA (3)
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_ANTENNA (4)
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_PCT1 (5)
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_PCT2 (6)

#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PERMUTATION_ID (0)
#define BLE_SVC_RAS_FILTER_MODE2_TONE_PCT (1)
#define BLE_SVC_RAS_FILTER_MODE2_TONE_QUALITY (2)
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_1 (3)
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_2 (4)
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_3 (5)
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_4 (6)

#define BLE_SVC_RAS_FILTER_MODE3_PACKET_QUALITY (0)
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_NADM (1)
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_RSSI (2)
#define BLE_SVC_RAS_FILTER_MODE3_TOD_TOA (3)
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_ANTENNA (4)
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_PCT1 (5)
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_PCT2 (6)
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PERMUTATION_ID (7)
#define BLE_SVC_RAS_FILTER_MODE3_TONE_PCT (8)
#define BLE_SVC_RAS_FILTER_MODE3_TONE_QUALITY (9)
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_1 (10)
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_2 (11)
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_3 (12)
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_4 (13)

#define BLE_SVC_RAS_CP_CMD_GET_RANGING_DATA (0x00)
#define BLE_SVC_RAS_CP_CMD_ACK_RANGING_DATA (0x01)
#define BLE_SVC_RAS_CP_CMD_RETRIEVE_LOST_SEGMENT (0x02)
#define BLE_SVC_RAS_CP_CMD_ABORT_OPERATION (0x03)
#define BLE_SVC_RAS_CP_CMD_SET_FILTER (0x04)

#define BLE_SVC_RAS_CP_RSP_COMPLETE_RANGING_DATA (0x00)
#define BLE_SVC_RAS_CP_RSP_COMPLETE_LOST_SEGMENT (0x01)
#define BLE_SVC_RAS_CP_RSP_RESPONSE_CODE (0x02)

#define BLE_SVC_RAS_CP_RSPCODE_SUCCESS (0x01)
#define BLE_SVC_RAS_CP_RSPCODE_OP_CODE_NOT_SUPPORTED (0x02)
#define BLE_SVC_RAS_CP_RSPCODE_INVALID_PARAMETER (0x03)
#define BLE_SVC_RAS_CP_RSPCODE_SUCCESS_PERSISTED (0x04)
#define BLE_SVC_RAS_CP_RSPCODE_ABORT_UNSUCCESSFUL (0x05)
#define BLE_SVC_RAS_CP_RSPCODE_PROCEDURE_NOT_COMPLETED (0x06)
#define BLE_SVC_RAS_CP_RSPCODE_SERVER_BUSY (0x07)
#define BLE_SVC_RAS_CP_RSPCODE_NO_RECORDS_FOUND (0x08)

#define BLE_SVC_RAS_MODE_REAL_TIME (0)
#define BLE_SVC_RAS_MODE_ON_DEMAND (1)

#if MYNEWT_VAL(BLE_SVC_RAS_SERVER)
void ble_svc_ras_init(void);
int ble_svc_ras_ranging_data_body_init(uint16_t conn_handle, uint16_t procedure_counter, uint8_t config_id,
uint8_t tx_power, uint8_t antenna_paths_mask);
int ble_svc_ras_ranging_subevent_init(uint16_t conn_handle, uint16_t start_acl_conn_event, uint16_t frequency_compensation,
uint8_t ranging_done_status, uint8_t subevent_done_status,
uint8_t ranging_abort_reason, uint8_t subevent_abort_reason,
uint8_t reference_power_level, uint8_t number_of_steps_reported);
int ble_svc_ras_ranging_subevent_update_status(uint16_t conn_handle, uint8_t number_of_steps_reported,
uint8_t ranging_done_status, uint8_t subevent_done_status,
uint8_t ranging_abort_reason, uint8_t subevent_abort_reason);
int ble_svc_ras_add_step_mode(uint16_t conn_handle, uint8_t mode, uint8_t status);
int ble_svc_ras_add_mode0_result(struct ble_cs_mode0_result *result, uint16_t conn_handle, uint8_t local_role);
int ble_svc_ras_add_mode1_result(struct ble_cs_mode1_result *result, uint16_t conn_handle, uint8_t rtt_pct_included);
int ble_svc_ras_add_mode2_result(struct ble_cs_mode2_result *result, uint16_t conn_handle, uint8_t n_ap);
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);
int ble_svc_ras_ranging_data_ready(uint16_t conn_handle);
#endif

#if MYNEWT_VAL(BLE_SVC_RAS_CLIENT)
struct ble_svc_ras_clt_ranging_header {
uint16_t ranging_counter;
uint8_t config_id;
uint8_t tx_power;
uint8_t antenna_paths_mask;
};

struct ble_svc_ras_clt_subevent_header {
uint16_t start_acl_conn_event;
uint16_t frequency_compensation;
uint8_t done_status;
uint8_t abort_reason;
uint8_t reference_power_level;
uint8_t number_of_steps_reported;
};

typedef void ble_svc_ras_clt_subscribe_cb(uint16_t conn_handle);
typedef void ble_svc_ras_clt_step_data_received_cb(void *data, uint16_t conn_handle, uint8_t step_mode);
int ble_svc_ras_clt_config_set(uint16_t conn_handle, uint8_t rtt_pct_included, uint8_t n_ap, uint8_t local_role);
int ble_svc_ras_clt_subscribe(ble_svc_ras_clt_subscribe_cb *subscribe_cb,
ble_svc_ras_clt_step_data_received_cb *step_data_cb,
uint16_t conn_handle, uint8_t mode);
#endif
#ifdef __cplusplus
}
#endif

#endif
43 changes: 43 additions & 0 deletions nimble/host/services/ras/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

pkg.name: nimble/host/services/ras
pkg.description: Implements the RAS Service.
pkg.author: "Apache Mynewt <[email protected]>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- ble
- bluetooth
- nimble
- ras

pkg.deps:
- nimble/host

pkg.init.'BLE_SVC_RAS_SERVER':
ble_svc_ras_init: 'MYNEWT_VAL(BLE_SVC_RAS_SYSINIT_STAGE)'

pkg.init.'BLE_SVC_RAS_CLIENT':
ble_svc_ras_clt_init: 'MYNEWT_VAL(BLE_SVC_RAS_SYSINIT_STAGE)'

pkg.source_files.'BLE_SVC_RAS_SERVER':
- "src/ble_svc_ras.c"

pkg.source_files.'BLE_SVC_RAS_CLIENT':
- "src/ble_svc_ras_clt.c"
Loading