Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | /*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <net/buf.h>
/** Identifiers of the signature supported by the RPC */
enum {
SIG_TYPE_NONE = 1,
SIG_TYPE_S,
SIG_TYPE_P,
SIG_TYPE_S_B,
SIG_TYPE_B_B_P,
SIG_TYPE_S_P,
SIG_TYPE_S_B_P,
SIG_TYPE_S_B_B_P,
SIG_TYPE_CONTROL = 0xFF
};
/**
* RPC memory allocation function, must be implemented by the user of the RPC.
*
* This function is called by the RPC mechanism to allocate a buffer for
* transmission of a serialized function. The function should not fail.
*
* @param length Length of the buffer to allocate.
*
* @return Pointer to the allocated buffer, the allocation shall not fail,
* error must be handled internally
*/
struct net_buf *rpc_alloc_cb(u16_t length);
/**
* RPC transmission function, must be implemented by the user of the RPC.
*
* @param buf Pointer to the buffer allocated for transmission
* by @ref rpc_alloc_cb
*/
void rpc_transmit_cb(struct net_buf *buf);
/**
* RPC initialization function that notifies the peer with an initialization
* packet containing the information to check the compatibility of the
* frameworks.
*
* @param version Local version to send to the peer.
*/
void rpc_init(u32_t version);
/**
* RPC initialization packet reception function, can optionally be implemented
* by the user of the RPC. If this function is not implemented, it will default
* to an empty function.
*
* This function is called by the RPC mechanism when an initialization packet is
* received from the connected peer.
*
* @param version Peer advertised version.
* @param compatible True if the peer runs a compatible RPC framework.
*/
void rpc_init_cb(u32_t version, bool compatible);
/** RPC serialize hash number generation.
*
* @return The unique identifier of the RPC deserialization.
*/
u32_t rpc_serialize_hash(void);
/**
* RPC serialization function to serialize a function that does not require any
* parameter.
*
* @param fn_index Index of the function
*/
void rpc_serialize_none(u8_t fn_index);
/**
* RPC serialization function to serialize a function that expects a structure
* as parameter.
*
* @param fn_index Index of the function
* @param struct_data Pointer to the structure to serialize
* @param struct_length Length of the structure to serialize
*/
void rpc_serialize_s(u8_t fn_index, const void *struct_data,
u8_t struct_length);
/**
* RPC serialization function to serialize a function that expects a structure
* and a pointer as parameters.
*
* @param fn_index Index of the function
* @param struct_data Pointer to the structure to serialize
* @param struct_length Length of the structure to serialize
* @param p_priv Pointer to serialize
*/
void rpc_serialize_s_p(u8_t fn_index, const void *struct_data,
u8_t struct_length, void *p_priv);
/**
* RPC serialization function to serialize a function that expects a pointer as
* parameter.
*
* @param fn_index Index of the function
* @param p_priv Pointer to serialize
*/
void rpc_serialize_p(u8_t fn_index, void *p_priv);
/**
* RPC serialization function to serialize a function that expects a structure
* and a buffer as parameters.
*
* @param fn_index Index of the function
* @param struct_data Pointer to the structure to serialize
* @param struct_length Length of the structure to serialize
* @param vbuf Pointer to the buffer to serialize
* @param vbuf_length Length of the buffer to serialize
*/
void rpc_serialize_s_b(u8_t fn_index, const void *struct_data,
u8_t struct_length, const void *vbuf,
u16_t vbuf_length);
/**
* RPC serialization function to serialize a function that expects a structure
* and a buffer as parameters.
*
* @param fn_index Index of the function
* @param vbuf1 Pointer to the buffer1 to serialize
* @param vbuf1_length Length of the buffer1 to serialize
* @param vbuf2 Pointer to the buffer2 to serialize
* @param vbuf2_length Length of the buffer2 to serialize
* @param p_priv Pointer to serialize
*/
void rpc_serialize_b_b_p(u8_t fn_index, const void *vbuf1,
u16_t vbuf1_length, const void *vbuf2,
u16_t vbuf2_length, void *p_priv);
/**
* RPC serialization function to serialize a function that expects a structure
* and a buffer as parameters.
*
* @param fn_index Index of the function
* @param struct_data Pointer to the structure to serialize
* @param struct_length Length of the structure to serialize
* @param vbuf Pointer to the buffer to serialize
* @param vbuf_length Length of the buffer to serialize
* @param p_priv Pointer to serialize
*/
void rpc_serialize_s_b_p(u8_t fn_index, const void *struct_data,
u8_t struct_length, const void *vbuf,
u16_t vbuf_length, void *p_priv);
/**
* RPC serialization function to serialize a function that expects a structure
* and a buffer as parameters.
*
* @param fn_index Index of the function
* @param struct_data Pointer to the structure to serialize
* @param struct_length Length of the structure to serialize
* @param vbuf1 Pointer to the buffer1 to serialize
* @param vbuf1_length Length of the buffer1 to serialize
* @param vbuf2 Pointer to the buffer2 to serialize
* @param vbuf2_length2 Length of the buffer2 to serialize
* @param p_priv Pointer to serialize
*/
void rpc_serialize_s_b_b_p(u8_t fn_index, const void *struct_data,
u8_t struct_length, const void *vbuf1,
u16_t vbuf1_length, const void *vbuf2,
u16_t vbuf2_length, void *p_priv);
/**
* RPC deserialization function, shall be invoked when a buffer is received
* over the transport interface.
*
* @param buf Pointer to the received buffer
*/
void rpc_deserialize(struct net_buf *buf);
/** RPC deserialize hash number generation.
*
* @return The unique identifier of the RPC deserialization.
*/
u32_t rpc_deserialize_hash(void);
|