Lines Matching refs:client

53 static int send_data(int sock, struct tftpc *client, uint32_t block_no, const uint8_t *data_buffer,  in send_data()  argument
72 sys_put_be16(DATA_OPCODE, client->tftp_buf); in send_data()
73 sys_put_be16(block_no, client->tftp_buf + 2); in send_data()
74 memcpy(client->tftp_buf + TFTP_HEADER_SIZE, data_buffer, data_size); in send_data()
76 ret = zsock_send(sock, client->tftp_buf, data_size + TFTP_HEADER_SIZE, 0); in send_data()
96 ret = zsock_recv(sock, client->tftp_buf, TFTPC_MAX_BUF_SIZE, 0); in send_data()
106 uint16_t opcode = sys_get_be16(client->tftp_buf); in send_data()
107 uint16_t blockno = sys_get_be16(client->tftp_buf + 2); in send_data()
119 if (client->callback) { in send_data()
124 evt.param.error.msg = client->tftp_buf + TFTP_HEADER_SIZE; in send_data()
126 client->callback(&evt); in send_data()
145 static inline int send_err(int sock, struct tftpc *client, int err_code, char *err_msg) in send_err() argument
152 sys_put_be16(ERROR_OPCODE, client->tftp_buf); in send_err()
153 sys_put_be16(err_code, client->tftp_buf + 2); in send_err()
160 if (copy_len > sizeof(client->tftp_buf) - req_size) { in send_err()
161 copy_len = sizeof(client->tftp_buf) - req_size; in send_err()
164 memcpy(client->tftp_buf + req_size, err_msg, copy_len); in send_err()
169 return zsock_send(sock, client->tftp_buf, req_size, 0); in send_err()
182 static int send_request(int sock, struct tftpc *client, in send_request() argument
190 req_size = make_request(client->tftp_buf, request, remote_file, mode); in send_request()
199 ret = zsock_sendto(sock, client->tftp_buf, req_size, 0, &client->server, in send_request()
200 ADDRLEN(client->server)); in send_request()
222 ret = zsock_recvfrom(sock, client->tftp_buf, TFTPC_MAX_BUF_SIZE, 0, in send_request()
225 req_size = make_request(client->tftp_buf, request, in send_request()
244 int tftp_get(struct tftpc *client, const char *remote_file, const char *mode) in tftp_get() argument
257 if (client == NULL) { in tftp_get()
261 sock = zsock_socket(client->server.sa_family, SOCK_DGRAM, IPPROTO_UDP); in tftp_get()
268 ret = send_request(sock, client, READ_REQUEST, remote_file, mode); in tftp_get()
273 uint16_t opcode = sys_get_be16(client->tftp_buf); in tftp_get()
274 uint16_t block_no = sys_get_be16(client->tftp_buf + 2); in tftp_get()
280 if (client->callback) { in tftp_get()
285 evt.param.error.msg = client->tftp_buf + TFTP_HEADER_SIZE; in tftp_get()
287 client->callback(&evt); in tftp_get()
304 if (client->callback == NULL) { in tftp_get()
306 if (send_err(sock, client, TFTP_ERROR_DISK_FULL, NULL) < 0) { in tftp_get()
319 evt.param.data.data_ptr = client->tftp_buf + TFTP_HEADER_SIZE; in tftp_get()
321 client->callback(&evt); in tftp_get()
359 ret = zsock_recv(sock, client->tftp_buf, TFTPC_MAX_BUF_SIZE, 0); in tftp_get()
372 int tftp_put(struct tftpc *client, const char *remote_file, const char *mode, in tftp_put() argument
382 if (client == NULL || user_buf == NULL || user_buf_size == 0) { in tftp_put()
386 sock = zsock_socket(client->server.sa_family, SOCK_DGRAM, IPPROTO_UDP); in tftp_put()
393 ret = send_request(sock, client, WRITE_REQUEST, remote_file, mode); in tftp_put()
397 uint16_t opcode = sys_get_be16(client->tftp_buf); in tftp_put()
398 uint16_t block_no = sys_get_be16(client->tftp_buf + 2); in tftp_put()
403 if (client->callback) { in tftp_put()
408 evt.param.error.msg = client->tftp_buf + TFTP_HEADER_SIZE; in tftp_put()
410 client->callback(&evt); in tftp_put()
433 ret = send_data(sock, client, tftpc_block_no, send_buffer, send_size); in tftp_put()