mesh: client relay proxy msgs [a2490]

This commit is contained in:
Milanka Ringwald 2019-12-09 11:47:21 +01:00
parent 57a9eeaef5
commit 1937dd5208
3 changed files with 106 additions and 2 deletions

View File

@ -2970,4 +2970,15 @@ typedef uint8_t sm_key_t[16];
*/
#define MESH_SUBEVENT_FOUNDATION_GATT_PROXY_STATUS 0x39
/**
* @format 121111
* @param subevent_code
* @param dest
* @param foundation_status
* @param relay
* @param retransmit_count the number of times that packet is transmitted for each packet that is relayed.
* @param retransmit_interval_ms retransmission interval in ms
*/
#define MESH_SUBEVENT_FOUNDATION_RELAY_STATUS 0x40
#endif

View File

@ -1534,6 +1534,7 @@ static inline uint16_t l2cap_event_ertm_buffer_released_get_local_cid(const uint
return little_endian_read_16(event, 2);
}
/**
* @brief Get field status from event RFCOMM_EVENT_CHANNEL_OPENED
* @param event packet
@ -8165,6 +8166,52 @@ static inline uint8_t mesh_subevent_foundation_gatt_proxy_status_get_gatt_proxy_
return event[6];
}
/**
* @brief Get field dest from event MESH_SUBEVENT_FOUNDATION_RELAY_STATUS
* @param event packet
* @return dest
* @note: btstack_type 2
*/
static inline uint16_t mesh_subevent_foundation_relay_status_get_dest(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field foundation_status from event MESH_SUBEVENT_FOUNDATION_RELAY_STATUS
* @param event packet
* @return foundation_status
* @note: btstack_type 1
*/
static inline uint8_t mesh_subevent_foundation_relay_status_get_foundation_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field relay from event MESH_SUBEVENT_FOUNDATION_RELAY_STATUS
* @param event packet
* @return relay
* @note: btstack_type 1
*/
static inline uint8_t mesh_subevent_foundation_relay_status_get_relay(const uint8_t * event){
return event[6];
}
/**
* @brief Get field retransmit_count from event MESH_SUBEVENT_FOUNDATION_RELAY_STATUS
* @param event packet
* @return retransmit_count
* @note: btstack_type 1
*/
static inline uint8_t mesh_subevent_foundation_relay_status_get_retransmit_count(const uint8_t * event){
return event[7];
}
/**
* @brief Get field retransmit_interval_ms from event MESH_SUBEVENT_FOUNDATION_RELAY_STATUS
* @param event packet
* @return retransmit_interval_ms
* @note: btstack_type 1
*/
static inline uint8_t mesh_subevent_foundation_relay_status_get_retransmit_interval_ms(const uint8_t * event){
return event[8];
}
/* API_END */

View File

@ -101,7 +101,7 @@ static const mesh_access_message_t mesh_configuration_client_gatt_proxy_set = {
MESH_FOUNDATION_OPERATION_GATT_PROXY_SET, "1"
};
#if 0
static const mesh_access_message_t mesh_configuration_client_relay_get = {
MESH_FOUNDATION_OPERATION_RELAY_GET, ""
};
@ -109,7 +109,7 @@ static const mesh_access_message_t mesh_configuration_client_relay_set = {
MESH_FOUNDATION_OPERATION_RELAY_SET, "11"
};
#if 0
static const mesh_access_message_t mesh_configuration_client_publication_get = {
MESH_FOUNDATION_OPERATION_MODEL_PUBLICATION_GET, "2m"
};
@ -204,6 +204,30 @@ uint8_t mesh_configuration_client_send_gatt_proxy_set(mesh_model_t * mesh_model,
return ERROR_CODE_SUCCESS;
}
uint8_t mesh_configuration_client_send_relay_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index){
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_network_pdu_t * network_pdu = mesh_access_setup_unsegmented_message(&mesh_configuration_client_relay_get);
if (!network_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) network_pdu, MESH_FOUNDATION_OPERATION_RELAY_GET);
return ERROR_CODE_SUCCESS;
}
uint8_t mesh_configuration_client_send_relay_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t relay, uint8_t relay_retransmit_count, uint8_t relay_retransmit_interval_steps){
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
if (relay_retransmit_count > 0x07) return ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE;
if (relay_retransmit_interval_steps > 0x1F) return ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE;
mesh_network_pdu_t * network_pdu = mesh_access_setup_unsegmented_message(&mesh_configuration_client_relay_set, relay, (relay_retransmit_count << 5) | relay_retransmit_interval_steps);
if (!network_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) network_pdu, MESH_FOUNDATION_OPERATION_RELAY_SET);
return ERROR_CODE_SUCCESS;
}
// Model Operations
static void mesh_configuration_client_beacon_status_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
@ -296,11 +320,33 @@ static void mesh_configuration_client_gatt_proxy_handler(mesh_model_t *mesh_mode
mesh_access_message_processed(pdu);
}
static void mesh_configuration_client_relay_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
mesh_access_parser_state_t parser;
mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu);
uint8_t relay = mesh_access_parser_get_u8(&parser);
uint8_t retransmition = mesh_access_parser_get_u8(&parser);
uint8_t event[9] = {HCI_EVENT_MESH_META, 5, MESH_SUBEVENT_FOUNDATION_RELAY_STATUS};
int pos = 3;
// dest
little_endian_store_16(event, pos, mesh_pdu_src(pdu));
pos += 2;
event[pos++] = ERROR_CODE_SUCCESS;
event[pos++] = relay;
event[pos++] = (retransmition >> 5) + 1;
event[pos++] = ((retransmition & 0x07) + 1) * 10;
(*mesh_model->model_packet_handler)(HCI_EVENT_PACKET, 0, event, pos);
mesh_access_message_processed(pdu);
}
const static mesh_operation_t mesh_configuration_client_model_operations[] = {
{ MESH_FOUNDATION_OPERATION_BEACON_STATUS, 1, mesh_configuration_client_beacon_status_handler },
{ MESH_FOUNDATION_OPERATION_COMPOSITION_DATA_STATUS, 1, mesh_configuration_client_composition_data_status_handler },
{ MESH_FOUNDATION_OPERATION_DEFAULT_TTL_STATUS, 1, mesh_configuration_client_default_ttl_handler },
{ MESH_FOUNDATION_OPERATION_GATT_PROXY_STATUS, 1, mesh_configuration_client_gatt_proxy_handler },
{ MESH_FOUNDATION_OPERATION_RELAY_STATUS, 2, mesh_configuration_client_relay_handler },
{ 0, 0, NULL }
};