Skip to content

Commit

Permalink
framework/ble_manager: Add interface (ble_manager_set_server_config) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hs36-kim authored Feb 19, 2025
1 parent d5d4f69 commit d644f4b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions framework/src/ble_manager/ble_manager_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ ble_result_e ble_client_operation_write_no_response(ble_client_ctx *ctx, ble_att
}

/* Server */
ble_result_e ble_manager_set_server_config(ble_server_init_config *server_config)
{
blemgr_msg_s msg = {BLE_CMD_SET_SERVER_CONFIG, BLE_MANAGER_FAIL, (void *)(server_config), NULL};
int res = blemgr_post_message(&msg);

RETURN_RESULT(res, msg);
}

ble_result_e ble_server_get_profile_count(uint16_t *count)
{
blemgr_msg_s msg = {BLE_CMD_GET_PROFILE_COUNT, BLE_MANAGER_FAIL, (void *)(count), NULL};
Expand Down
1 change: 1 addition & 0 deletions framework/src/ble_manager/ble_manager_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef enum {
BLE_CMD_OP_WRITE_NO_RESP,

// Server
BLE_CMD_SET_SERVER_CONFIG,
BLE_CMD_GET_PROFILE_COUNT,
BLE_CMD_CHARACT_NOTI,
BLE_CMD_CHARACT_INDI,
Expand Down
10 changes: 10 additions & 0 deletions framework/src/ble_manager/ble_manager_lwnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ trble_result_e ble_drv_operation_write_no_response(trble_operation_handle *handl
}

/*** Peripheral(Server) ***/
trble_result_e ble_drv_set_server_config(uint16_t *server_config)
{
trble_result_e res = TRBLE_SUCCESS;
lwnl_msg msg = {BLE_INTF_NAME, {LWNL_REQ_BLE_SET_SERVER_CONFIG}, sizeof(uint16_t *), (void *)server_config, (void *)&res};
if (_send_msg(&msg) < 0) {
res = TRBLE_FILE_ERROR;
}
return res;
}

trble_result_e ble_drv_get_profile_count(uint16_t *count)
{
trble_result_e res = TRBLE_SUCCESS;
Expand Down
7 changes: 7 additions & 0 deletions framework/src/ble_manager/ble_manager_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,13 @@ ble_result_e blemgr_handle_request(blemgr_msg_s *msg)
} break;

// Server
case BLE_CMD_SET_SERVER_CONFIG: {
BLE_STATE_CHECK;

trble_server_init_config *server = (trble_server_init_config *)msg->param;
ret = ble_drv_set_server_config(server);
} break;

case BLE_CMD_GET_PROFILE_COUNT: {
BLE_STATE_CHECK;

Expand Down
3 changes: 3 additions & 0 deletions os/include/tinyara/net/if/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ typedef enum {
LWNL_REQ_BLE_OP_WRITE_NO_RESP,

// Server
LWNL_REQ_BLE_SET_SERVER_CONFIG,
LWNL_REQ_BLE_GET_PROFILE_COUNT,
LWNL_REQ_BLE_CHARACT_NOTI,
LWNL_REQ_BLE_CHARACT_INDI,
Expand Down Expand Up @@ -390,6 +391,7 @@ typedef trble_result_e (*trble_operation_write)(struct bledev *dev, trble_operat
typedef trble_result_e (*trble_operation_write_no_response)(struct bledev *dev, trble_operation_handle *handle, trble_data *in_data);

/*** Peripheral(Server) ***/
typedef trble_result_e (*trble_set_server_config)(struct bledev *dev, trble_server_init_config *server);
typedef trble_result_e (*trble_get_profile_count)(struct bledev *dev, uint16_t *count);
// API for sending a characteristic value notification to the selected target(s). (notify to all clients conn_handle (notify all = 0x99))
typedef trble_result_e (*trble_charact_notify)(struct bledev *dev, trble_attr_handle attr_handle, trble_conn_handle con_handle, trble_data *data);
Expand Down Expand Up @@ -463,6 +465,7 @@ struct trble_ops {
trble_operation_write_no_response op_wrtie_no_resp;

/* Peripheral(Server) */
trble_set_server_config set_server_config;
trble_get_profile_count get_profile_count;
trble_charact_notify charact_noti;
trble_charact_indicate charact_indi;
Expand Down
13 changes: 13 additions & 0 deletions os/net/blemgr/bledev.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ int bledev_handle(struct bledev *dev, lwnl_req cmd, void *data, uint32_t data_le
break;

//Server
case LWNL_REQ_BLE_SET_SERVER_CONFIG:
{
lwnl_msg_params param = { 0, };
if (data != NULL) {
memcpy(&param, data, data_len);
} else {
return TRBLE_INVALID_ARGS;
}

trble_server_init_config *t_server = (trble_server_init_config *)param.param[0];

TRBLE_DRV_CALL(ret, dev, set_server_config, (dev, t_server));
}
case LWNL_REQ_BLE_GET_PROFILE_COUNT:
{
uint16_t *count = NULL;
Expand Down

0 comments on commit d644f4b

Please sign in to comment.