32 uint8_t *cmdBuf = NULL;
40 uint8_t *cmdBuf = (uint8_t*)malloc(expectedLen);
44 LOGF0(
"Failed to allocate command bytes: %zd", expectedLen);
47 request->message.message.commandbytes.data = cmdBuf;
50 &request->message.command, cmdBuf);
52 request->message.message.commandbytes.len = packedLen;
53 request->message.message.has_commandbytes =
true;
55 .data = request->message.message.commandbytes.data,
56 .len = request->message.message.commandbytes.len,
73 uint8_t **out_msg,
size_t *msgSize)
76 Com__Seagate__Kinetic__Proto__Message* proto = &operation->request->message.message;
81 header.valueLength = operation->value.len;
88 uint8_t *msg = malloc(
PDU_HEADER_LEN + header.protobufLength + header.valueLength);
91 LOG0(
"Failed to allocate outgoing message!");
96 KineticRequest* request = operation->request;
97 msg[offset] = header.versionPrefix;
98 offset +=
sizeof(header.versionPrefix);
99 memcpy(&msg[offset], &nboProtoLength,
sizeof(nboProtoLength));
100 offset +=
sizeof(nboProtoLength);
101 memcpy(&msg[offset], &nboValueLength,
sizeof(nboValueLength));
102 offset +=
sizeof(nboValueLength);
105 offset += header.protobufLength;
109 LOGF2(
"[PDU TX] pdu: %p, session: %p, bus: %p, "
110 "fd: %6d, seq: %8lld, protoLen: %8u, valueLen: %8u, op: %p, msgType: %02x",
111 (
void*)operation->request,
112 (
void*)operation->session, (
void*)operation->session->messageBus,
113 operation->session->socket, (
long long)request->message.header.sequence,
114 header.protobufLength, header.valueLength,
115 (
void*)operation, request->message.header.messagetype);
121 if (header.valueLength > 0) {
122 memcpy(&msg[offset], operation->value.data, operation->value.len);
123 offset += operation->value.len;
133 uint8_t *msg,
size_t msgSize)
138 .
fd = operation->session->socket,
140 .seq_id = operation->request->message.header.sequence,
145 .timeout_sec = operation->timeoutSeconds,
153 return 0 == pthread_mutex_lock(&session->sendMutex);
159 return 0 == pthread_mutex_unlock(&session->sendMutex);
Structure for handling generic arrays of bytes.
void KineticLogger_LogHeader(int log_level, const KineticPDUHeader *header)
KineticStatus KineticRequest_PackMessage(KineticOperation *operation, uint8_t **out_msg, size_t *msgSize)
KineticStatus KineticRequest_PopulateAuthentication(KineticSessionConfig *config, KineticRequest *request, ByteArray *pin)
uint32_t KineticNBO_FromHostU32(uint32_t valueHost)
Structure used to specify the configuration for a session.
void KineticController_HandleResult(bus_msg_result_t *res, void *udata)
bool Bus_SendRequest(struct bus *b, bus_user_msg *msg)
Send a request.
size_t KineticRequest_PackCommand(KineticRequest *request)
Failed allocating/deallocating memory.
bool KineticRequest_LockSend(KineticSession *session)
size_t com__seagate__kinetic__proto__command__get_packed_size(const Com__Seagate__Kinetic__Proto__Command *message)
KineticStatus KineticAuth_PopulatePin(KineticSessionConfig const *const config, KineticRequest *const pdu, ByteArray pin)
#define KINETIC_ASSERT(cond)
#define LOGF0(message,...)
void KineticLogger_LogProtobuf(int log_level, const Com__Seagate__Kinetic__Proto__Message *msg)
KineticStatus
Kinetic status codes.
size_t com__seagate__kinetic__proto__command__pack(const Com__Seagate__Kinetic__Proto__Command *message, uint8_t *out)
void KineticLogger_LogByteArray(int log_level, const char *title, ByteArray bytes)
KineticStatus KineticAuth_PopulateHmac(KineticSessionConfig const *const config, KineticRequest *const pdu)
#define KINETIC_REQUEST_PACK_FAILURE
size_t com__seagate__kinetic__proto__message__pack(const Com__Seagate__Kinetic__Proto__Message *message, uint8_t *out)
size_t com__seagate__kinetic__proto__message__get_packed_size(const Com__Seagate__Kinetic__Proto__Message *message)
bool KineticRequest_SendRequest(KineticOperation *operation, uint8_t *msg, size_t msgSize)
bool KineticRequest_UnlockSend(KineticSession *session)
#define LOGF2(message,...)