modem: hl7800: fix socket port byte order
Ensure the proper byte order is used for the network socket in the stack. When sending the AT commands, the port needs to be converted to host endianess. TLS handshakes check that the remote address and port match what is expected. Signed-off-by: Ryan Erickson <ryan.erickson@ezurio.com>
This commit is contained in:
parent
d8a1fd93e0
commit
39412e26c8
1 changed files with 13 additions and 15 deletions
|
|
@ -1440,7 +1440,7 @@ static int send_data(struct hl7800_socket *sock, struct net_pkt *pkt)
|
|||
}
|
||||
snprintk(buf, sizeof(buf), "AT+KUDPSND=%d,\"%s\",%u,%zu",
|
||||
sock->socket_id, dst_addr,
|
||||
net_sin(&sock->dst)->sin_port, send_len);
|
||||
ntohs(net_sin(&sock->dst)->sin_port), send_len);
|
||||
}
|
||||
send_at_cmd(sock, buf, K_NO_WAIT, 0, false);
|
||||
|
||||
|
|
@ -1590,8 +1590,8 @@ static int pkt_setup_ip_data(struct net_pkt *pkt, struct hl7800_socket *sock)
|
|||
}
|
||||
net_pkt_set_remote_address(pkt, &sock->dst, sizeof(struct sockaddr_in6));
|
||||
pkt->remote.sa_family = AF_INET6;
|
||||
src_port = ntohs(net_sin6(&sock->src)->sin6_port);
|
||||
dst_port = ntohs(net_sin6(&sock->dst)->sin6_port);
|
||||
src_port = net_sin6(&sock->src)->sin6_port;
|
||||
dst_port = net_sin6(&sock->dst)->sin6_port;
|
||||
|
||||
hdr_len = sizeof(struct net_ipv6_hdr);
|
||||
}
|
||||
|
|
@ -1605,8 +1605,8 @@ static int pkt_setup_ip_data(struct net_pkt *pkt, struct hl7800_socket *sock)
|
|||
}
|
||||
net_pkt_set_remote_address(pkt, &sock->dst, sizeof(struct sockaddr_in));
|
||||
pkt->remote.sa_family = AF_INET;
|
||||
src_port = ntohs(net_sin(&sock->src)->sin_port);
|
||||
dst_port = ntohs(net_sin(&sock->dst)->sin_port);
|
||||
src_port = net_sin(&sock->src)->sin_port;
|
||||
dst_port = net_sin(&sock->dst)->sin_port;
|
||||
|
||||
hdr_len = sizeof(struct net_ipv4_hdr);
|
||||
}
|
||||
|
|
@ -5782,10 +5782,10 @@ static int configure_TCP_socket(struct hl7800_socket *sock)
|
|||
|
||||
if (sock->dst.sa_family == AF_INET6) {
|
||||
af = MDM_HL7800_SOCKET_AF_IPV6;
|
||||
dst_port = net_sin6(&sock->dst)->sin6_port;
|
||||
dst_port = ntohs(net_sin6(&sock->dst)->sin6_port);
|
||||
} else if (sock->dst.sa_family == AF_INET) {
|
||||
af = MDM_HL7800_SOCKET_AF_IPV4;
|
||||
dst_port = net_sin(&sock->dst)->sin_port;
|
||||
dst_port = ntohs(net_sin(&sock->dst)->sin_port);
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -6006,7 +6006,7 @@ static int offload_connect(struct net_context *context,
|
|||
if (addr->sa_family == AF_INET6) {
|
||||
net_ipaddr_copy(&net_sin6(&sock->dst)->sin6_addr,
|
||||
&net_sin6(addr)->sin6_addr);
|
||||
dst_port = ntohs(net_sin6(addr)->sin6_port);
|
||||
dst_port = net_sin6(addr)->sin6_port;
|
||||
net_sin6(&sock->dst)->sin6_port = dst_port;
|
||||
} else
|
||||
#endif
|
||||
|
|
@ -6014,7 +6014,7 @@ static int offload_connect(struct net_context *context,
|
|||
if (addr->sa_family == AF_INET) {
|
||||
net_ipaddr_copy(&net_sin(&sock->dst)->sin_addr,
|
||||
&net_sin(addr)->sin_addr);
|
||||
dst_port = ntohs(net_sin(addr)->sin_port);
|
||||
dst_port = net_sin(addr)->sin_port;
|
||||
net_sin(&sock->dst)->sin_port = dst_port;
|
||||
} else
|
||||
#endif
|
||||
|
|
@ -6023,7 +6023,7 @@ static int offload_connect(struct net_context *context,
|
|||
}
|
||||
|
||||
if (dst_port < 0) {
|
||||
LOG_ERR("Invalid port: %d", dst_port);
|
||||
LOG_ERR("Invalid port: %d", ntohs(dst_port));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -6074,7 +6074,7 @@ static int offload_sendto(struct net_pkt *pkt, const struct sockaddr *dst_addr,
|
|||
{
|
||||
struct net_context *context = net_pkt_context(pkt);
|
||||
struct hl7800_socket *sock;
|
||||
int ret, dst_port = 0;
|
||||
int ret;
|
||||
|
||||
if (!context) {
|
||||
return -EINVAL;
|
||||
|
|
@ -6090,16 +6090,14 @@ static int offload_sendto(struct net_pkt *pkt, const struct sockaddr *dst_addr,
|
|||
if (dst_addr->sa_family == AF_INET6) {
|
||||
net_ipaddr_copy(&net_sin6(&sock->dst)->sin6_addr,
|
||||
&net_sin6(dst_addr)->sin6_addr);
|
||||
dst_port = ntohs(net_sin6(dst_addr)->sin6_port);
|
||||
net_sin6(&sock->dst)->sin6_port = dst_port;
|
||||
net_sin6(&sock->dst)->sin6_port = net_sin6(dst_addr)->sin6_port;
|
||||
} else
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
if (dst_addr->sa_family == AF_INET) {
|
||||
net_ipaddr_copy(&net_sin(&sock->dst)->sin_addr,
|
||||
&net_sin(dst_addr)->sin_addr);
|
||||
dst_port = ntohs(net_sin(dst_addr)->sin_port);
|
||||
net_sin(&sock->dst)->sin_port = dst_port;
|
||||
net_sin(&sock->dst)->sin_port = net_sin(dst_addr)->sin_port;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue