Skip to content

Commit 452cf7d

Browse files
LG-73 Partial CDD API support
Includes support for the following: - Setting an item (WPC_set_config_data_item) - Getting an item (WPC_get_config_data_item) - Registering a callback for an item indication (WPC_register_for_config_data_item)
1 parent 6a435a3 commit 452cf7d

File tree

7 files changed

+325
-0
lines changed

7 files changed

+325
-0
lines changed

lib/api/wpc.h

+64
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,41 @@ app_res_e WPC_send_data(const uint8_t * bytes,
925925
*/
926926
app_res_e WPC_send_data_with_options(const app_message_t * message_p);
927927

928+
/**
929+
* \brief Set config data item
930+
* \param endpoint
931+
* Endpoint address of the config data item
932+
* \param payload
933+
* Pointer to the new config data payload
934+
* \param size
935+
* Size of the new payload to write (bytes)
936+
* \return Return code of the operation
937+
* \note This call can only be made from a sink node.
938+
* An optional config data item can be removed by setting a zero-size
939+
* payload.
940+
*/
941+
app_res_e WPC_set_config_data_item(const uint16_t endpoint,
942+
const uint8_t *const payload,
943+
const uint8_t size);
944+
945+
/**
946+
* \brief Get config data item
947+
* \param endpoint
948+
* Endpoint address of the config data item to get
949+
* \param payload
950+
* Pointer to read config data item payload into
951+
* \param payload_capacity
952+
* Allocated size of the given payload buffer (bytes). If received
953+
* payload is larger, the function fails.
954+
* \param size
955+
* Size of the payload that was written to the above pointer (bytes)
956+
* \return Return code of the operation
957+
*/
958+
app_res_e WPC_get_config_data_item(const uint16_t endpoint,
959+
uint8_t *const payload,
960+
const size_t payload_capacity,
961+
uint8_t *const size);
962+
928963
/**
929964
* \brief Callback definition to register for received data
930965
* \param bytes
@@ -1045,4 +1080,33 @@ app_res_e WPC_register_for_stack_status(onStackStatusReceived_cb_f onStackStatus
10451080
*/
10461081
app_res_e WPC_unregister_from_stack_status();
10471082

1083+
/**
1084+
* \brief Callback definition to register for config data item notification
1085+
* \param endpoint
1086+
* Endpoint address of the configuration data item
1087+
* \param payload
1088+
* Pointer to the configuration data
1089+
* \param size
1090+
* Size of the configuration data (bytes)
1091+
*/
1092+
typedef void (*onConfigDataItemReceived_cb_f)(const uint16_t endpoint,
1093+
const uint8_t *const payload,
1094+
const uint8_t size);
1095+
1096+
/**
1097+
* \brief Register for receiving config data item
1098+
* \param onConfigDataItemReceived
1099+
* The callback to call when config data item is received
1100+
* \note All the registered callback share the same thread,
1101+
* so the handling of it must be kept as simple
1102+
* as possible or dispatched to another thread for long operations.
1103+
*/
1104+
app_res_e WPC_register_for_config_data_item(onConfigDataItemReceived_cb_f onConfigDataItemReceived);
1105+
1106+
/**
1107+
* \brief Unregister for receiving config data item
1108+
* \return Return code of the operation
1109+
*/
1110+
app_res_e WPC_unregister_from_config_data_item();
1111+
10481112
#endif

lib/wpc/include/msap.h

+82
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ typedef struct __attribute__((__packed__))
192192
uint8_t bytes[MAXIMUM_SCRATCHPAD_BLOCK_SIZE];
193193
} msap_image_block_read_conf_pl_t;
194194

195+
typedef struct __attribute__((__packed__))
196+
{
197+
uint16_t endpoint;
198+
uint8_t payload_length;
199+
uint8_t payload[MAXIMUM_CDC_ITEM_PAYLOAD_SIZE];
200+
} msap_config_data_item_set_req_pl_t;
201+
202+
typedef struct __attribute__((__packed__))
203+
{
204+
uint16_t endpoint;
205+
} msap_config_data_item_get_req_pl_t;
206+
207+
typedef struct __attribute__((__packed__))
208+
{
209+
uint8_t result;
210+
uint8_t payload_length;
211+
uint8_t payload[MAXIMUM_CDC_ITEM_PAYLOAD_SIZE];
212+
} msap_config_data_item_get_conf_pl_t;
213+
214+
typedef struct __attribute__((__packed__))
215+
{
216+
uint8_t indication_status;
217+
uint16_t endpoint;
218+
uint8_t payload_length;
219+
uint8_t payload[MAXIMUM_CDC_ITEM_PAYLOAD_SIZE];
220+
} msap_config_data_item_rx_ind_pl_t;
221+
195222
static inline void
196223
convert_internal_to_app_scratchpad_status(app_scratchpad_status_t * status_p,
197224
msap_scratchpad_status_conf_pl_t * internal_status_p)
@@ -448,6 +475,40 @@ static inline int msap_attribute_read_request(uint16_t attribute_id,
448475
return attribute_read_request(MSAP_ATTRIBUTE_READ_REQUEST, attribute_id, attribute_length, attribute_value_p);
449476
}
450477

478+
/**
479+
* \brief Request to set config data item
480+
* \param endpoint
481+
* Endpoint address of the config data item
482+
* \param payload
483+
* Pointer to the new config data payload
484+
* \param payload_size
485+
* Size of the new payload to write (bytes)
486+
* \return Negative value upon internal error, otherwise result code returned
487+
* by the DualMCU API
488+
*/
489+
int msap_config_data_item_set_request(const uint16_t endpoint,
490+
const uint8_t *const payload,
491+
const uint8_t payload_size);
492+
493+
/**
494+
* \brief Request to get config data item
495+
* \param endpoint
496+
* Endpoint address of the config data item to get
497+
* \param payload
498+
* Pointer to the read config data payload
499+
* \param payload_capacity
500+
* Allocated size of the given payload buffer (bytes). If received
501+
* payload is larger, the function fails.
502+
* \param payload_size
503+
* Size of the payload that was read (bytes)
504+
* \return Negative value upon internal error, otherwise result code returned
505+
* by the DualMCU API
506+
*/
507+
int msap_config_data_item_get_request(const uint16_t endpoint,
508+
uint8_t *const payload,
509+
const size_t payload_capacity,
510+
uint8_t *const payload_size);
511+
451512
/**
452513
* \brief Handler for stack state indication
453514
* \param payload
@@ -469,6 +530,13 @@ void msap_app_config_data_rx_indication_handler(msap_app_config_data_rx_ind_pl_t
469530
*/
470531
void msap_scan_nbors_indication_handler(msap_scan_nbors_ind_pl_t * payload);
471532

533+
/**
534+
* \brief Handler for config data item receive
535+
* \param payload
536+
* pointer to payload
537+
*/
538+
void msap_config_data_item_rx_indication_handler(msap_config_data_item_rx_ind_pl_t * payload);
539+
472540
/**
473541
* \brief Register for app config data
474542
* \param cb
@@ -511,4 +579,18 @@ bool msap_register_for_stack_status(onStackStatusReceived_cb_f cb);
511579
*/
512580
bool msap_unregister_from_stack_status();
513581

582+
/**
583+
* \brief Register for config data item
584+
* \param cb
585+
* Callback to invoke when config data item is received
586+
* \return True if registered successfully, false otherwise
587+
*/
588+
bool msap_register_for_config_data_item(onConfigDataItemReceived_cb_f cb);
589+
590+
/**
591+
* \brief Unregister for config data item
592+
* \return True if unregistered successfully, false otherwise
593+
*/
594+
bool msap_unregister_from_config_data_item();
595+
514596
#endif /* MSAP_H_ */

lib/wpc/include/wpc_constants.h

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
#define MSAP_SCRATCH_TARGET_READ_CONFIRM (SAP_CONFIRM_OFFSET + MSAP_SCRATCH_TARGET_READ_REQUEST)
8787
#define MSAP_SCRATCH_BLOCK_READ_REQUEST 0x28
8888
#define MSAP_SCRATCH_BLOCK_READ_CONFIRM (SAP_CONFIRM_OFFSET + MSAP_SCRATCH_BLOCK_READ_REQUEST)
89+
#define MSAP_CONFIG_DATA_ITEM_SET_REQUEST 0x29
90+
#define MSAP_CONFIG_DATA_ITEM_SET_CONFIRM (SAP_CONFIRM_OFFSET + MSAP_CONFIG_DATA_ITEM_SET_REQUEST)
91+
#define MSAP_CONFIG_DATA_ITEM_GET_REQUEST 0x30
92+
#define MSAP_CONFIG_DATA_ITEM_GET_CONFIRM (SAP_CONFIRM_OFFSET + MSAP_CONFIG_DATA_ITEM_GET_REQUEST)
93+
#define MSAP_CONFIG_DATA_ITEM_RX_INDICATION 0x31
94+
#define MSAP_CONFIG_DATA_ITEM_RX_RESPONSE (SAP_RESPONSE_OFFSET + MSAP_CONFIG_DATA_ITEM_RX_INDICATION)
8995

9096
/*
9197
* Configuration Service Access Points
@@ -118,6 +124,8 @@
118124
/* Maximun Full packet size for all platforms */
119125
#define MAX_FULL_PACKET_SIZE 1500
120126

127+
#define MAXIMUM_CDC_ITEM_PAYLOAD_SIZE 80
128+
#define MAXIMUM_CDC_ITEM_LIST_BYTE_COUNT 32
121129

122130
#endif
123131

lib/wpc/include/wpc_types.h

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef struct __attribute__((__packed__))
6565
csap_factory_reset_req_pl_t csap_factory_reset_request_payload;
6666
msap_scratchpad_target_write_req_pl_t msap_scratchpad_target_write_request_payload;
6767
msap_image_block_read_req_pl_t msap_image_block_read_request_payload;
68+
msap_config_data_item_set_req_pl_t msap_config_data_item_set_request_payload;
69+
msap_config_data_item_get_req_pl_t msap_config_data_item_get_request_payload;
6870
// Indication
6971
dsap_data_tx_ind_pl_t dsap_data_tx_indication_payload;
7072
dsap_data_rx_ind_pl_t dsap_data_rx_indication_payload;
@@ -73,6 +75,7 @@ typedef struct __attribute__((__packed__))
7375
msap_app_config_data_rx_ind_pl_t msap_app_config_data_rx_indication_payload;
7476
msap_scan_nbors_ind_pl_t msap_scan_nbors_indication_payload;
7577
generic_ind_pl_t generic_indication_payload;
78+
msap_config_data_item_rx_ind_pl_t msap_config_data_item_rx_indication_payload;
7679
// Confirm
7780
sap_generic_conf_pl_t sap_generic_confirm_payload;
7881
dsap_data_tx_conf_pl_t dsap_data_tx_confirm_payload;
@@ -84,11 +87,16 @@ typedef struct __attribute__((__packed__))
8487
attribute_read_conf_pl_t attribute_read_confirm_payload;
8588
msap_scratchpad_target_read_conf_pl_t msap_scratchpad_target_read_confirm_payload;
8689
msap_image_block_read_conf_pl_t msap_image_block_read_confirm_payload;
90+
msap_config_data_item_get_conf_pl_t msap_config_data_item_get_confirm_payload;
8791
// Response
8892
sap_resp_pl_t sap_response_payload;
8993
} payload;
9094
} wpc_frame_t;
9195

96+
// Make sure each member of the payload union has a size representable by the
97+
// payload_length field
98+
_Static_assert(sizeof(((wpc_frame_t*)0)->payload) <= UINT8_MAX, "");
99+
92100
// Size of a given frame
93101
#define FRAME_SIZE(__frame_ptr__) ((__frame_ptr__)->payload_length + 3)
94102

lib/wpc/msap.c

+108
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ static onScanNeighborsDone_cb_f m_scan_neighbor_cb = NULL;
2929
*/
3030
static onStackStatusReceived_cb_f m_stack_status_cb = NULL;
3131

32+
/**
33+
* \brief Registered callback for config data item
34+
*/
35+
static onConfigDataItemReceived_cb_f m_config_data_item_cb = NULL;
36+
3237
/**
3338
* \brief Time to wait for scratchpad start request confirm
3439
* It can be long because the start triggers an erase of
@@ -448,6 +453,85 @@ int msap_scratchpad_block_read_request(uint32_t start_address, uint8_t number_of
448453
return confirm.payload.msap_image_block_read_confirm_payload.result;
449454
}
450455

456+
int msap_config_data_item_set_request(const uint16_t endpoint,
457+
const uint8_t *const payload,
458+
const uint8_t payload_size)
459+
{
460+
if (payload_size > MAXIMUM_CDC_ITEM_PAYLOAD_SIZE)
461+
{
462+
LOGE("Too large payload size (%d) for config data item\n", payload_size);
463+
return WPC_INT_WRONG_PARAM_ERROR;
464+
}
465+
466+
wpc_frame_t request = {
467+
.primitive_id = MSAP_CONFIG_DATA_ITEM_SET_REQUEST,
468+
.payload_length = sizeof(msap_config_data_item_set_req_pl_t),
469+
.payload = {
470+
.msap_config_data_item_set_request_payload = {
471+
.endpoint = endpoint,
472+
.payload_length = payload_size,
473+
.payload = {0}
474+
}
475+
}
476+
};
477+
478+
memcpy(request.payload.msap_config_data_item_set_request_payload.payload,
479+
payload,
480+
payload_size);
481+
482+
wpc_frame_t confirm;
483+
const int res = WPC_Int_send_request(&request, &confirm);
484+
if (res < 0)
485+
{
486+
return res;
487+
}
488+
489+
return confirm.payload.sap_generic_confirm_payload.result;
490+
}
491+
492+
int msap_config_data_item_get_request(const uint16_t endpoint,
493+
uint8_t *const payload,
494+
const size_t payload_capacity,
495+
uint8_t *const payload_size)
496+
{
497+
wpc_frame_t request = {
498+
.primitive_id = MSAP_CONFIG_DATA_ITEM_GET_REQUEST,
499+
.payload_length = sizeof(msap_config_data_item_get_req_pl_t),
500+
.payload = {
501+
.msap_config_data_item_get_request_payload = {
502+
.endpoint = endpoint,
503+
}
504+
}
505+
};
506+
507+
wpc_frame_t confirm;
508+
const int res = WPC_Int_send_request(&request, &confirm);
509+
if (res < 0)
510+
{
511+
return res;
512+
}
513+
514+
if (confirm.payload.sap_generic_confirm_payload.result == 0)
515+
{
516+
const uint8_t payload_length = confirm.payload.msap_config_data_item_get_confirm_payload.payload_length;
517+
if (payload_length > payload_capacity)
518+
{
519+
return WPC_INT_WRONG_BUFFER_SIZE;
520+
}
521+
if (payload_length > sizeof(confirm.payload.msap_config_data_item_get_confirm_payload.payload))
522+
{
523+
return WPC_INT_WRONG_PARAM_ERROR;
524+
}
525+
526+
memcpy(payload,
527+
&confirm.payload.msap_config_data_item_get_confirm_payload.payload,
528+
payload_length);
529+
*payload_size = payload_length;
530+
}
531+
532+
return confirm.payload.sap_generic_confirm_payload.result;
533+
}
534+
451535
void msap_stack_state_indication_handler(msap_stack_state_ind_pl_t * payload)
452536
{
453537
LOGI("Status is 0x%02x\n", payload->status);
@@ -479,6 +563,20 @@ void msap_scan_nbors_indication_handler(msap_scan_nbors_ind_pl_t * payload)
479563
}
480564
}
481565

566+
void msap_config_data_item_rx_indication_handler(msap_config_data_item_rx_ind_pl_t * payload)
567+
{
568+
LOGI("Received configuration data item indication for endpoint: %04X\n",
569+
payload->endpoint);
570+
571+
if (m_config_data_item_cb != NULL)
572+
{
573+
m_config_data_item_cb(payload->endpoint,
574+
payload->payload,
575+
payload->payload_length);
576+
577+
}
578+
}
579+
482580
// Macro to avoid code duplication
483581
#define REGISTER_CB(cb, internal_cb) \
484582
({ \
@@ -537,3 +635,13 @@ bool msap_unregister_from_stack_status()
537635
{
538636
return UNREGISTER_CB(m_stack_status_cb);
539637
}
638+
639+
bool msap_register_for_config_data_item(onConfigDataItemReceived_cb_f cb)
640+
{
641+
return REGISTER_CB(cb, m_config_data_item_cb);
642+
}
643+
644+
bool msap_unregister_from_config_data_item()
645+
{
646+
return UNREGISTER_CB(m_config_data_item_cb);
647+
}

0 commit comments

Comments
 (0)