Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 740da204 authored by Ayush Singh's avatar Ayush Singh
Browse files

Add more svc request handlers


Added SVC requests which have empty payload responses

Signed-off-by: default avatarAyush Singh <ayushsingh1325@gmail.com>
parent 21796f3f
1 merge request!2HDLC MR
Pipeline #4711 passed with stage
in 1 minute and 33 seconds
...@@ -12,14 +12,21 @@ ...@@ -12,14 +12,21 @@
#define GB_SVC_VERSION_MAJOR 0x00 #define GB_SVC_VERSION_MAJOR 0x00
#define GB_SVC_VERSION_MINOR 0x01 #define GB_SVC_VERSION_MINOR 0x01
#define OP_RESPONSE 0x80
/* Greybus SVC request types */ /* Greybus SVC request types */
#define GB_SVC_TYPE_PROTOCOL_VERSION_REQUEST 0x01 #define GB_SVC_TYPE_PROTOCOL_VERSION_REQUEST 0x01
#define GB_SVC_TYPE_PROTOCOL_VERSION_RESPONSE 0x81 #define GB_SVC_TYPE_PROTOCOL_VERSION_RESPONSE OP_RESPONSE | GB_SVC_TYPE_PROTOCOL_VERSION_REQUEST
#define GB_SVC_TYPE_HELLO_REQUEST 0x02 #define GB_SVC_TYPE_HELLO_REQUEST 0x02
#define GB_SVC_TYPE_HELLO_RESPONSE 0x82 #define GB_SVC_TYPE_HELLO_RESPONSE OP_RESPONSE | GB_SVC_TYPE_HELLO_REQUEST
#define GB_SVC_TYPE_PING_REQUEST 0x13 #define GB_SVC_TYPE_PING_REQUEST 0x13
#define GB_SVC_TYPE_PING_RESPONSE 0x93 #define GB_SVC_TYPE_PING_RESPONSE OP_RESPONSE | GB_SVC_TYPE_PING_REQUEST
#define GB_SVC_TYPE_INTF_DEVICE_ID_REQUEST 0x03
#define GB_SVC_TYPE_INTF_DEVICE_ID_RESPONSE OP_RESPONSE | GB_SVC_TYPE_INTF_DEVICE_ID_REQUEST
#define GB_SVC_TYPE_ROUTE_CREATE_REQUEST 0x0b
#define GB_SVC_TYPE_ROUTE_CREATE_RESPONSE OP_RESPONSE | GB_SVC_TYPE_ROUTE_CREATE_REQUEST
#define GB_SVC_TYPE_ROUTE_DESTROY_REQUEST 0x0c
#define GB_SVC_TYPE_ROUTE_DESTROY_RESPONSE OP_RESPONSE | GB_SVC_TYPE_ROUTE_DESTROY_REQUEST
/* /*
* All operation messages (both requests and responses) begin with * All operation messages (both requests and responses) begin with
......
...@@ -60,10 +60,10 @@ struct gb_connection *gb_create_connection(struct gb_interface *inf_ap, ...@@ -60,10 +60,10 @@ struct gb_connection *gb_create_connection(struct gb_interface *inf_ap,
return conn; return conn;
} }
struct gb_message *gb_message_request_alloc(const void *payload, static struct gb_message *gb_message_alloc(const void *payload,
size_t payload_len, size_t payload_len,
uint8_t request_type, uint8_t message_type,
bool is_oneshot) { uint16_t operation_id) {
struct gb_message *msg; struct gb_message *msg;
msg = k_malloc(sizeof(struct gb_message) + payload_len); msg = k_malloc(sizeof(struct gb_message) + payload_len);
...@@ -73,11 +73,27 @@ struct gb_message *gb_message_request_alloc(const void *payload, ...@@ -73,11 +73,27 @@ struct gb_message *gb_message_request_alloc(const void *payload,
} }
msg->header.size = sizeof(struct gb_operation_msg_hdr) + payload_len; msg->header.size = sizeof(struct gb_operation_msg_hdr) + payload_len;
msg->header.id = is_oneshot ? 0 : new_operation_id(); msg->header.id = operation_id;
msg->header.type = request_type; msg->header.type = message_type;
msg->header.status = 0; msg->header.status = 0;
msg->payload_size = payload_len; msg->payload_size = payload_len;
memcpy(msg->payload, payload, msg->payload_size); memcpy(msg->payload, payload, msg->payload_size);
return msg; return msg;
} }
struct gb_message *gb_message_request_alloc(const void *payload,
size_t payload_len,
uint8_t request_type,
bool is_oneshot) {
uint16_t operation_id = is_oneshot ? 0 : new_operation_id();
return gb_message_alloc(payload, payload_len, request_type, operation_id);
}
struct gb_message *gb_message_response_alloc(const void *payload,
size_t payload_len,
uint8_t request_type,
uint16_t operation_id) {
return gb_message_alloc(payload, payload_len, OP_RESPONSE | request_type,
operation_id);
}
...@@ -158,4 +158,17 @@ struct gb_connection *gb_create_connection(struct gb_interface *, ...@@ -158,4 +158,17 @@ struct gb_connection *gb_create_connection(struct gb_interface *,
struct gb_message *gb_message_request_alloc(const void *, size_t, uint8_t, struct gb_message *gb_message_request_alloc(const void *, size_t, uint8_t,
bool); bool);
/*
* Allocate a greybus response message
*
* @param Payload
* @param Payload len
* @param Request Type
* @param Operation ID
*
* @return greybus message allocated on heap. Null in case of errro
*/
struct gb_message *gb_message_response_alloc(const void *, size_t, uint8_t,
uint16_t);
#endif #endif
...@@ -71,12 +71,28 @@ static void svc_ping_response_handler(struct gb_message *msg) { ...@@ -71,12 +71,28 @@ static void svc_ping_response_handler(struct gb_message *msg) {
LOG_DBG("Received Pong"); LOG_DBG("Received Pong");
} }
static void svc_hello_response(struct gb_message *msg) { static void svc_hello_response_handler(struct gb_message *msg) {
LOG_DBG("Hello Response Success"); LOG_DBG("Hello Response Success");
} }
static void svc_empty_request_handler(struct gb_message *msg) {
struct gb_message *resp =
gb_message_response_alloc(NULL, 0, msg->header.type, msg->header.id);
if (resp == NULL) {
LOG_DBG("Failed to allocate response for %X", msg->header.type);
return;
}
k_fifo_put(&svc_ctrl_data.pending_read, resp);
}
static void gb_handle_msg(struct gb_message *msg) { static void gb_handle_msg(struct gb_message *msg) {
switch (msg->header.type) { switch (msg->header.type) {
case GB_SVC_TYPE_INTF_DEVICE_ID_REQUEST:
case GB_SVC_TYPE_ROUTE_CREATE_REQUEST:
case GB_SVC_TYPE_ROUTE_DESTROY_REQUEST:
case GB_SVC_TYPE_PING_REQUEST:
svc_empty_request_handler(msg);
break;
case GB_SVC_TYPE_PROTOCOL_VERSION_RESPONSE: case GB_SVC_TYPE_PROTOCOL_VERSION_RESPONSE:
svc_version_response_handler(msg); svc_version_response_handler(msg);
break; break;
...@@ -84,7 +100,7 @@ static void gb_handle_msg(struct gb_message *msg) { ...@@ -84,7 +100,7 @@ static void gb_handle_msg(struct gb_message *msg) {
svc_ping_response_handler(msg); svc_ping_response_handler(msg);
break; break;
case GB_SVC_TYPE_HELLO_RESPONSE: case GB_SVC_TYPE_HELLO_RESPONSE:
svc_hello_response(msg); svc_hello_response_handler(msg);
break; break;
default: default:
LOG_WRN("Handling SVC operation Type %X not supported yet", LOG_WRN("Handling SVC operation Type %X not supported yet",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment