2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef OTHERSERVICE_RPCUDP_H_ // NOLINT(build/header_guard)
18 #define OTHERSERVICE_RPCUDP_H_ // NOLINT(build/header_guard)
20 /** @addtogroup RPClib_in */
22 /** Number of bytes of payload that can be stored in a UDP packet */
23 #define RPC_UDP_PAYLOAD RPC_MAX_API_ARG_TOTAL_SIZE
27 * Packet type, source ID, sequence number, packet size, packet position
29 #define RPC_PACKET_HEADER "%-2d %-5x %-8x %-4u %1d "
30 /** Number of bytes in the UDP packet header
32 #define RPC_PACKET_HEADER_LEN (2+1 + 5+1 + 8+1 + 4+1 + 1+1)
34 /** Number of bytes to store in the UDP packet */
35 #define RPC_UDP_PACKET_SIZE (RPC_UDP_PAYLOAD + RPC_PACKET_HEADER_LEN)
37 #define RPC_COMMAND_LEN 3
39 /** Format string for UDP packet header analysis */
40 #define RPC_PACKET_HEADER_scanf "%d %x %x %d"
42 /** Header (API number) to be added to the API call packet */
43 #define RPC_APICALL_FORMAT "%-4d "
44 /** Number of bytes in the header of an API call packet */
45 #define RPC_APICALL_FORMAT_ARGS_START 5
47 #define RPC_MAX_RESPONSE_MESSAGE_SIZE 5
49 #define RPC_SEQ_NUM_START 1
50 #define RPC_SEQ_NUM_INVALID 0
52 /** Internal API call number for checking server existence */
53 #define RPC_API_NUM_RPC_ALIVE 0
55 /** Type of packet that the RPC library sends */
57 RPC_PACKET_APICALL = 0,/**< API call request */
59 RPC_RESPONSE_APICALL,/**< Responding to API Call Requests */
60 #define RPC_RESPONSE_NONE 0x0000
61 #define RPC_RESPONSE_API_OK 0x0001
62 #define RPC_RESPONSE_API_BUSY 0x0002
63 #define RPC_RESPONSE_API_ERR 0x0004
64 #define RPC_RESPONSE_API_DEADLOCK 0x0005 /* Server deadlock */
65 #define RPC_RESPONSE_API_CERTIFY 0x0006 /* Authentication request */
67 RPC_PACKET_APIRETURN,/**< Result of the API call */
72 /** Packet Location (Multi-Fragment Packet Support) */
74 RPC_PACKET_POS_ONEANDONLY = 0,/**< Complete with one packet */
75 } rpc_packet_position;
77 /** Transmitting buffer */
83 /** Valid bytes in the sockaddr_un struct specified for send */
84 #define RPC_SOCKET_NAME_LEN 6 /**< Name: 5 characters + first NULL bytes */
85 #define RPC_SOCKET_ADDR_LEN (sizeof(short) + RPC_SOCKET_NAME_LEN) // NOLINT (readability/nolint)
90 RPC_SEND_TO_SERVER_NO_RETRY,
95 int RpcSendUdp(struct RpcIdInfo *id, RPC_ID receiver, int direction,
96 RPC_packet_type type, const void *mesg, unsigned int bytes);
97 int RpcSendUdp2(struct RpcIdInfo *id, RPC_ID receiver, int direction,
98 RPC_packet_type type, unsigned int num, rpc_send_buf *sendbuf);
99 RPC_Result RpcSendUdpResponse(struct RpcIdInfo *id, RPC_ID receiver,
101 RPC_packet_type type,
102 UINT32 seq_num, char *mesg, UINT32 bytes);
104 int RpcReadUdpPacket(const struct RpcIdInfo *id, UINT8 *buf);
106 RPC_Result RpcParsePacketHeader(const char *str, RPC_packet_type *command,
107 RPC_ID_p id, UINT32 *seq_num, UINT32 *size);
109 RPC_Result RpcClientWaitResponse(struct RpcIdInfo *idinfo,
111 UINT32 timeout_msec, UINT16 *response);
112 RPC_Result RpcClientWaitResult(struct RpcIdInfo *idinfo, RPC_ID srvr_id);
114 #if defined(RPC_USE_UNIX_AUTOBIND)
115 /* ===pathname of datagram sockets for API requests=== */
117 RpcSetServerName(char *str, RPC_ID id) {
119 sprintf(str + 1, "S%04x", id); // NOLINT (readability/nolint)
123 RpcSetClientName(char *str, RPC_ID id) {
125 sprintf(str + 1, "%05x", id); // NOLINT (readability/nolint)
129 RpcGetClientName(const char *str, RPC_ID *id) {
131 memcpy(buf, str + 1, 5);
134 *id = (RPC_ID)(strtoul(buf + 1, NULL, 16));
136 *id = (RPC_ID)(strtoul(buf, NULL, 16));
140 /* ===pathname of stream-socket for authenticating=== */
142 RpcSetServerSecureName(char *str, RPC_ID id) {
144 sprintf(str + 1, "secure_S%04x", id); // NOLINT (readability/nolint)
148 RpcSetClientSecureName(char *str, RPC_ID id) {
150 sprintf(str + 1, "secure_%05x", id); // NOLINT (readability/nolint)
154 RpcGetClientNameFromSock(const char *str, char *client_sock_name) {
155 memcpy(client_sock_name, str + 8, 5);
156 client_sock_name[5] = '\0';
159 #endif /* !AUTOBIND */
162 #endif // OTHERSERVICE_RPCUDP_H_