Add proto arg to patty_ax25_sock_new()

Other changes:

    * Remove proto arg from patty_ax25_sock_send() and
      patty_ax25_sock_write(); instead, use the proto member of
      patty_ax25_sock
This commit is contained in:
XANTRONIX Development 2020-07-02 16:07:23 -04:00 committed by XANTRONIX Industrial
parent 085ac4e650
commit c6aac035e1
7 changed files with 30 additions and 22 deletions

View file

@ -19,6 +19,7 @@ enum patty_ax25_call {
*/ */
typedef struct _patty_ax25_call_socket_request { typedef struct _patty_ax25_call_socket_request {
int opts; int opts;
int proto;
} patty_ax25_call_socket_request; } patty_ax25_call_socket_request;
typedef struct _patty_ax25_response_socket { typedef struct _patty_ax25_response_socket {
@ -29,6 +30,7 @@ typedef struct _patty_ax25_response_socket {
int patty_ax25_call_socket(int server, int patty_ax25_call_socket(int server,
int opts, int opts,
int proto,
char *path, char *path,
size_t len); size_t len);

View file

@ -27,6 +27,7 @@ typedef struct _patty_ax25_sock {
enum patty_ax25_sock_opts opts; enum patty_ax25_sock_opts opts;
enum patty_ax25_sock_status status; enum patty_ax25_sock_status status;
enum patty_ax25_sock_mode mode; enum patty_ax25_sock_mode mode;
enum patty_ax25_proto proto;
time_t timer_ack, time_t timer_ack,
timer_response, timer_response,
@ -65,7 +66,8 @@ typedef struct _patty_ax25_sock {
PATTY_AX25_SOCK_CONTROL_SABME(sock, flag): \ PATTY_AX25_SOCK_CONTROL_SABME(sock, flag): \
PATTY_AX25_SOCK_CONTROL_SABM(sock, flag)) PATTY_AX25_SOCK_CONTROL_SABM(sock, flag))
patty_ax25_sock *patty_ax25_sock_new(enum patty_ax25_sock_opts opts); patty_ax25_sock *patty_ax25_sock_new(enum patty_ax25_sock_opts opts,
enum patty_ax25_proto proto);
void patty_ax25_sock_reset(patty_ax25_sock *sock); void patty_ax25_sock_reset(patty_ax25_sock *sock);
@ -73,9 +75,11 @@ void patty_ax25_sock_destroy(patty_ax25_sock *sock);
char *patty_ax25_sock_pty(patty_ax25_sock *sock); char *patty_ax25_sock_pty(patty_ax25_sock *sock);
void patty_ax25_sock_bind_if(patty_ax25_sock *sock,
patty_ax25_if *iface);
ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
uint16_t control, uint16_t control,
uint8_t proto,
void *info, void *info,
size_t infolen); size_t infolen);
@ -86,7 +90,6 @@ ssize_t patty_ax25_sock_send_sabme(patty_ax25_sock *sock, int poll);
ssize_t patty_ax25_sock_send_disc(patty_ax25_sock *sock, int poll); ssize_t patty_ax25_sock_send_disc(patty_ax25_sock *sock, int poll);
ssize_t patty_ax25_sock_write(patty_ax25_sock *sock, ssize_t patty_ax25_sock_write(patty_ax25_sock *sock,
uint8_t proto,
void *buf, void *buf,
size_t len); size_t len);

View file

@ -7,12 +7,13 @@
int patty_ax25_call_socket(int server, int patty_ax25_call_socket(int server,
int opts, int opts,
int proto,
char *path, char *path,
size_t len) { size_t len) {
enum patty_ax25_call call = PATTY_AX25_CALL_SOCKET; enum patty_ax25_call call = PATTY_AX25_CALL_SOCKET;
patty_ax25_call_socket_request request = { patty_ax25_call_socket_request request = {
opts opts, proto
}; };
patty_ax25_call_socket_response response; patty_ax25_call_socket_response response;

View file

@ -441,7 +441,7 @@ static int server_socket(patty_ax25_server *server,
goto error_read; goto error_read;
} }
if ((sock = patty_ax25_sock_new(request.opts)) == NULL) { if ((sock = patty_ax25_sock_new(request.opts, request.proto)) == NULL) {
goto error_sock_new; goto error_sock_new;
} }
@ -1020,7 +1020,7 @@ static int handle_sabm(patty_ax25_server *server,
goto error_lookup_client; goto error_lookup_client;
} }
if ((remote = patty_ax25_sock_new(local->opts)) == NULL) { if ((remote = patty_ax25_sock_new(local->opts, local->proto)) == NULL) {
goto error_sock_new; goto error_sock_new;
} }
@ -1354,7 +1354,7 @@ static int handle_sock(void *key,
goto done; goto done;
} }
if (patty_ax25_sock_write(sock, PATTY_AX25_PROTO_NONE, sock->buf, len) < 0) { if (patty_ax25_sock_write(sock, sock->buf, len) < 0) {
goto error_sock_write; goto error_sock_write;
} }

View file

@ -56,7 +56,8 @@ error_open:
return -1; return -1;
} }
patty_ax25_sock *patty_ax25_sock_new(enum patty_ax25_sock_opts opts) { patty_ax25_sock *patty_ax25_sock_new(enum patty_ax25_sock_opts opts,
enum patty_ax25_proto proto) {
patty_ax25_sock *sock; patty_ax25_sock *sock;
if ((sock = malloc(sizeof(*sock))) == NULL) { if ((sock = malloc(sizeof(*sock))) == NULL) {
@ -77,6 +78,7 @@ patty_ax25_sock *patty_ax25_sock_new(enum patty_ax25_sock_opts opts) {
sock->status = PATTY_AX25_SOCK_CLOSED; sock->status = PATTY_AX25_SOCK_CLOSED;
sock->mode = PATTY_AX25_SOCK_DM; sock->mode = PATTY_AX25_SOCK_DM;
sock->opts = opts; sock->opts = opts;
sock->proto = proto;
sock->n_maxlen = PATTY_AX25_FRAME_DEFAULT_MAXLEN; sock->n_maxlen = PATTY_AX25_FRAME_DEFAULT_MAXLEN;
sock->n_window = PATTY_AX25_FRAME_DEFAULT_WINDOW; sock->n_window = PATTY_AX25_FRAME_DEFAULT_WINDOW;
@ -159,10 +161,10 @@ static inline int toobig(patty_ax25_sock *sock,
ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
uint16_t control, uint16_t control,
uint8_t proto,
void *info, void *info,
size_t infolen) { size_t infolen) {
size_t offset; size_t offset;
uint8_t *buf = (uint8_t *)sock->iface->tx_buf;
if (toobig(sock, control, infolen)) { if (toobig(sock, control, infolen)) {
goto error_toobig; goto error_toobig;
@ -171,24 +173,24 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
offset = copy_addr_to_tx_buf(sock); offset = copy_addr_to_tx_buf(sock);
if (sock->mode == PATTY_AX25_SOCK_SABME) { if (sock->mode == PATTY_AX25_SOCK_SABME) {
((uint8_t *)sock->iface->tx_buf)[offset++] = (control & 0xff00) >> 8; buf[offset++] = (control & 0xff00) >> 8;
((uint8_t *)sock->iface->tx_buf)[offset++] = control & 0x00ff; buf[offset++] = control & 0x00ff;
sock->seq_send = (sock->seq_send + 1) & 0x07; sock->seq_send = (sock->seq_send + 1) & 0x07;
} else { } else {
((uint8_t *)sock->iface->tx_buf)[offset++] = control; buf[offset++] = control;
sock->seq_send = (sock->seq_send + 1) & 0x7f; sock->seq_send = (sock->seq_send + 1) & 0x7f;
} }
if (PATTY_AX25_CONTROL_INFO(control)) { if (PATTY_AX25_CONTROL_INFO(control)) {
((uint8_t *)sock->iface->tx_buf)[offset++] = proto; buf[offset++] = (uint8_t)sock->proto;
memcpy((uint8_t *)sock->iface->tx_buf + offset, info, infolen); memcpy(buf + offset, info, infolen);
offset += infolen; offset += infolen;
} }
return patty_ax25_if_send(sock->iface, sock->iface->tx_buf, offset); return patty_ax25_if_send(sock->iface, buf, offset);
error_toobig: error_toobig:
return -1; return -1;
@ -198,7 +200,6 @@ ssize_t patty_ax25_sock_send_sabm(patty_ax25_sock *sock, int poll) {
return patty_ax25_sock_send(sock, return patty_ax25_sock_send(sock,
PATTY_AX25_FRAME_U_SABM PATTY_AX25_FRAME_U_SABM
| PATTY_AX25_FRAME_U_POLL, | PATTY_AX25_FRAME_U_POLL,
PATTY_AX25_PROTO_NONE,
NULL, NULL,
0); 0);
} }
@ -207,7 +208,6 @@ ssize_t patty_ax25_sock_send_sabme(patty_ax25_sock *sock, int poll) {
return patty_ax25_sock_send(sock, return patty_ax25_sock_send(sock,
PATTY_AX25_FRAME_U_SABME PATTY_AX25_FRAME_U_SABME
| PATTY_AX25_FRAME_U_POLL, | PATTY_AX25_FRAME_U_POLL,
PATTY_AX25_PROTO_NONE,
NULL, NULL,
0); 0);
} }
@ -216,17 +216,19 @@ ssize_t patty_ax25_sock_send_disc(patty_ax25_sock *sock, int poll) {
return patty_ax25_sock_send(sock, return patty_ax25_sock_send(sock,
PATTY_AX25_FRAME_U_DISC PATTY_AX25_FRAME_U_DISC
| PATTY_AX25_FRAME_U_POLL, | PATTY_AX25_FRAME_U_POLL,
PATTY_AX25_PROTO_NONE,
NULL, NULL,
0); 0);
} }
ssize_t patty_ax25_sock_write(patty_ax25_sock *sock, ssize_t patty_ax25_sock_write(patty_ax25_sock *sock,
uint8_t proto,
void *buf, void *buf,
size_t len) { size_t len) {
uint16_t control = 0x0000; uint16_t control = 0x0000;
if (sock->opts & PATTY_AX25_SOCK_RAW) {
return patty_ax25_if_send(sock->iface, buf, len);
}
switch (sock->mode) { switch (sock->mode) {
case PATTY_AX25_SOCK_DM: case PATTY_AX25_SOCK_DM:
errno = EBADF; errno = EBADF;
@ -244,7 +246,7 @@ ssize_t patty_ax25_sock_write(patty_ax25_sock *sock,
break; break;
} }
if (patty_ax25_sock_send(sock, control, proto, buf, len) < 0) { if (patty_ax25_sock_send(sock, control, buf, len) < 0) {
goto error_send; goto error_send;
} }

View file

@ -61,7 +61,7 @@ int main(int argc, char **argv) {
goto error_connect; goto error_connect;
} }
if ((sock = patty_ax25_call_socket(fd, PATTY_AX25_SOCK_NONE, path, PATTY_AX25_SOCK_PATH_SIZE)) < 0) { if ((sock = patty_ax25_call_socket(fd, 0, PATTY_AX25_PROTO_NONE, path, PATTY_AX25_SOCK_PATH_SIZE)) < 0) {
fprintf(stderr, "%s: %s: %s\n", fprintf(stderr, "%s: %s: %s\n",
argv[0], "patty_ax25_call_socket()", strerror(errno)); argv[0], "patty_ax25_call_socket()", strerror(errno));

View file

@ -64,7 +64,7 @@ int main(int argc, char **argv) {
goto error_connect; goto error_connect;
} }
if ((local = patty_ax25_call_socket(fd, PATTY_AX25_SOCK_NONE, NULL, 0)) < 0) { if ((local = patty_ax25_call_socket(fd, 0, PATTY_AX25_PROTO_NONE, NULL, 0)) < 0) {
fprintf(stderr, "%s: %s: %s\n", fprintf(stderr, "%s: %s: %s\n",
argv[0], "patty_ax25_call_socket()", strerror(errno)); argv[0], "patty_ax25_call_socket()", strerror(errno));