drivers: wifi: esp: access socket type and ip_proto from net_context

net_context contains both net_sock_type and net_ip_protocol, which are
static during the lifetime of net_context. net_context has basically the
ownership of esp_socket, so we can be sure 'type' and 'ip_proto' are
always accessible through net_context API.

Remove 'type' and 'ip_proto' members from 'esp_socket' structure, as
those are already accessible by net_context API.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
Marcin Niestroj 2020-12-02 17:30:55 +01:00 committed by Anas Nashif
parent cad292e17f
commit 705eb1d2b0
4 changed files with 19 additions and 17 deletions

View file

@ -458,7 +458,7 @@ static int cmd_ipd_check_hdr_end(struct esp_socket *sock, char actual)
char expected;
/* When using passive mode, the +IPD command ends with \r\n */
if (ESP_PROTO_PASSIVE(sock->ip_proto)) {
if (ESP_PROTO_PASSIVE(esp_socket_ip_proto(sock))) {
expected = '\r';
} else {
expected = ':';
@ -510,7 +510,7 @@ MODEM_CMD_DIRECT_DEFINE(on_cmd_ipd)
* When using passive TCP, the data itself is not included in the +IPD
* command but must be polled with AT+CIPRECVDATA.
*/
if (ESP_PROTO_PASSIVE(sock->ip_proto)) {
if (ESP_PROTO_PASSIVE(esp_socket_ip_proto(sock))) {
esp_socket_work_submit(sock, &sock->recvdata_work);
ret = data_offset;
goto socket_unref;

View file

@ -145,8 +145,6 @@ struct esp_socket {
atomic_t flags;
/* socket info */
enum net_sock_type type;
enum net_ip_protocol ip_proto;
struct sockaddr dst;
/* sem */
@ -230,8 +228,6 @@ struct esp_data {
int esp_offload_init(struct net_if *iface);
struct esp_socket *esp_socket_get(struct esp_data *data,
enum net_sock_type type,
enum net_ip_protocol ip_proto,
struct net_context *context);
int esp_socket_put(struct esp_socket *sock);
void esp_socket_init(struct esp_data *data);
@ -352,6 +348,16 @@ static inline bool esp_flags_are_set(struct esp_data *dev, uint8_t flags)
return (dev->flags & flags) != 0;
}
static inline enum net_sock_type esp_socket_type(struct esp_socket *sock)
{
return net_context_get_type(sock->context);
}
static inline enum net_ip_protocol esp_socket_ip_proto(struct esp_socket *sock)
{
return net_context_get_ip_proto(sock->context);
}
static inline int esp_cmd_send(struct esp_data *data,
const struct modem_cmd *handlers,
size_t handlers_len, const char *buf,

View file

@ -56,7 +56,7 @@ static int _sock_connect(struct esp_data *dev, struct esp_socket *sock)
&net_sin(&dst)->sin_addr,
addr_str, sizeof(addr_str));
if (sock->ip_proto == IPPROTO_TCP) {
if (esp_socket_ip_proto(sock) == IPPROTO_TCP) {
snprintk(connect_msg, sizeof(connect_msg),
"AT+CIPSTART=%d,\"TCP\",\"%s\",%d,7200",
sock->link_id, addr_str,
@ -69,13 +69,13 @@ static int _sock_connect(struct esp_data *dev, struct esp_socket *sock)
}
LOG_DBG("link %d, ip_proto %s, addr %s", sock->link_id,
sock->ip_proto == IPPROTO_TCP ? "TCP" : "UDP",
esp_socket_ip_proto(sock) == IPPROTO_TCP ? "TCP" : "UDP",
log_strdup(addr_str));
ret = esp_cmd_send(dev, NULL, 0, connect_msg, ESP_CMD_TIMEOUT);
if (ret == 0) {
esp_socket_flags_set(sock, ESP_SOCK_CONNECTED);
if (sock->type == SOCK_STREAM) {
if (esp_socket_type(sock) == SOCK_STREAM) {
net_context_set_state(sock->context,
NET_CONTEXT_CONNECTED);
}
@ -213,7 +213,7 @@ static int _sock_send(struct esp_socket *sock, struct net_pkt *pkt)
LOG_DBG("link %d, len %d", sock->link_id, pkt_len);
if (sock->ip_proto == IPPROTO_TCP) {
if (esp_socket_ip_proto(sock) == IPPROTO_TCP) {
snprintk(cmd_buf, sizeof(cmd_buf),
"AT+CIPSEND=%d,%d", sock->link_id, pkt_len);
} else {
@ -332,7 +332,7 @@ static int esp_sendto(struct net_pkt *pkt,
return -ENETUNREACH;
}
if (sock->type == SOCK_STREAM) {
if (esp_socket_type(sock) == SOCK_STREAM) {
if (!esp_socket_connected(sock)) {
return -ENOTCONN;
}
@ -600,7 +600,7 @@ static int esp_get(sa_family_t family,
*/
dev = &esp_driver_data;
sock = esp_socket_get(dev, type, ip_proto, *context);
sock = esp_socket_get(dev, *context);
if (!sock) {
LOG_ERR("No socket available!");
return -ENOMEM;

View file

@ -19,8 +19,6 @@ struct esp_workq_flush_data {
};
struct esp_socket *esp_socket_get(struct esp_data *data,
enum net_sock_type type,
enum net_ip_protocol ip_proto,
struct net_context *context)
{
struct esp_socket *sock = data->sockets;
@ -32,8 +30,6 @@ struct esp_socket *esp_socket_get(struct esp_data *data,
sock->context = context;
context->offload_context = sock;
sock->type = type;
sock->ip_proto = ip_proto;
sock->connect_cb = NULL;
sock->recv_cb = NULL;
@ -163,7 +159,7 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
pkt = esp_socket_prepare_pkt(sock, buf, offset, len);
if (!pkt) {
LOG_ERR("Failed to get net_pkt: len %zu", len);
if (sock->type == SOCK_STREAM) {
if (esp_socket_type(sock) == SOCK_STREAM) {
if (!esp_socket_flags_test_and_set(sock,
ESP_SOCK_CLOSE_PENDING)) {
esp_socket_work_submit(sock, &sock->close_work);