drivers/wifi: Switch winc1500 driver to new net_pkt API
Use tx and rx pools relevantly. Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
d086f50243
commit
e8b0e1f35b
1 changed files with 52 additions and 31 deletions
|
@ -119,6 +119,7 @@ typedef struct {
|
|||
|
||||
#define WINC1500_BIND_TIMEOUT 500
|
||||
#define WINC1500_LISTEN_TIMEOUT 500
|
||||
#define WINC1500_BUF_TIMEOUT 100
|
||||
|
||||
NET_BUF_POOL_DEFINE(winc1500_tx_pool, CONFIG_WIFI_WINC1500_BUF_CTR,
|
||||
CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE, 0, NULL);
|
||||
|
@ -453,24 +454,35 @@ static int winc1500_send(struct net_pkt *pkt,
|
|||
{
|
||||
struct net_context *context = pkt->context;
|
||||
SOCKET socket = (int)context->offload_context;
|
||||
struct net_buf *frag;
|
||||
int ret;
|
||||
int ret = 0;
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = net_buf_alloc(&winc1500_tx_pool, WINC1500_BUF_TIMEOUT);
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
w1500_data.socket_data[socket].send_cb = cb;
|
||||
w1500_data.socket_data[socket].send_user_data = user_data;
|
||||
|
||||
for (frag = pkt->frags; frag; frag = frag->frags) {
|
||||
ret = send(socket, frag->data, frag->len, 0);
|
||||
if (ret) {
|
||||
LOG_ERR("send error %d %s!",
|
||||
ret, socket_error_string(ret));
|
||||
return ret;
|
||||
}
|
||||
if (net_pkt_read_new(pkt, buf->data, net_pkt_get_len(pkt))) {
|
||||
ret = -ENOBUFS;
|
||||
goto out;
|
||||
}
|
||||
|
||||
net_buf_add(buf, net_pkt_get_len(pkt));
|
||||
|
||||
ret = send(socket, buf->data, buf->len, 0);
|
||||
if (ret) {
|
||||
LOG_ERR("send error %d %s!", ret, socket_error_string(ret));
|
||||
goto out;
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
out:
|
||||
net_buf_unref(buf);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -486,25 +498,36 @@ static int winc1500_sendto(struct net_pkt *pkt,
|
|||
{
|
||||
struct net_context *context = pkt->context;
|
||||
SOCKET socket = (int)context->offload_context;
|
||||
struct net_buf *frag;
|
||||
int ret;
|
||||
int ret = 0;
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = net_buf_alloc(&winc1500_tx_pool, WINC1500_BUF_TIMEOUT);
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
w1500_data.socket_data[socket].send_cb = cb;
|
||||
w1500_data.socket_data[socket].send_user_data = user_data;
|
||||
|
||||
for (frag = pkt->frags; frag; frag = frag->frags) {
|
||||
ret = sendto(socket, frag->data, frag->len, 0,
|
||||
(struct sockaddr *)dst_addr, addrlen);
|
||||
if (ret) {
|
||||
LOG_ERR("send error %d %s!",
|
||||
ret, socket_error_string(ret));
|
||||
return ret;
|
||||
}
|
||||
if (net_pkt_read_new(pkt, buf->data, net_pkt_get_len(pkt))) {
|
||||
ret = -ENOBUFS;
|
||||
goto out;
|
||||
}
|
||||
|
||||
net_buf_add(buf, net_pkt_get_len(pkt));
|
||||
|
||||
ret = sendto(socket, buf->data, buf->len, 0,
|
||||
(struct sockaddr *)dst_addr, addrlen);
|
||||
if (ret) {
|
||||
LOG_ERR("sendto error %d %s!", ret, socket_error_string(ret));
|
||||
goto out;
|
||||
}
|
||||
|
||||
net_pkt_unref(pkt);
|
||||
out:
|
||||
net_buf_unref(buf);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -512,21 +535,22 @@ static int winc1500_sendto(struct net_pkt *pkt,
|
|||
static int prepare_pkt(struct socket_data *sock_data)
|
||||
{
|
||||
/* Get the frame from the buffer */
|
||||
sock_data->rx_pkt = net_pkt_get_reserve_rx(K_NO_WAIT);
|
||||
sock_data->rx_pkt = net_pkt_rx_alloc_on_iface(w1500_data.iface,
|
||||
K_NO_WAIT);
|
||||
if (!sock_data->rx_pkt) {
|
||||
LOG_ERR("Could not allocate rx packet");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Reserve a data frag to receive the frame */
|
||||
sock_data->pkt_buf = net_pkt_get_frag(sock_data->rx_pkt, K_NO_WAIT);
|
||||
/* Reserve a data buffer to receive the frame */
|
||||
sock_data->pkt_buf = net_buf_alloc(&winc1500_rx_pool, K_NO_WAIT);
|
||||
if (!sock_data->pkt_buf) {
|
||||
LOG_ERR("Could not allocate data frag");
|
||||
LOG_ERR("Could not allocate data buffer");
|
||||
net_pkt_unref(sock_data->rx_pkt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
net_pkt_frag_insert(sock_data->rx_pkt, sock_data->pkt_buf);
|
||||
net_pkt_append_buffer(sock_data->rx_pkt, sock_data->pkt_buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -767,11 +791,8 @@ static bool handle_socket_msg_recv(SOCKET sock,
|
|||
tstrSocketRecvMsg *pstrRx = (tstrSocketRecvMsg *)pvMsg;
|
||||
|
||||
if ((pstrRx->pu8Buffer != NULL) && (pstrRx->s16BufferSize > 0)) {
|
||||
|
||||
net_buf_add(sd->pkt_buf, pstrRx->s16BufferSize);
|
||||
|
||||
net_pkt_set_appdata(sd->rx_pkt, sd->pkt_buf->data);
|
||||
net_pkt_set_appdatalen(sd->rx_pkt, pstrRx->s16BufferSize);
|
||||
net_pkt_cursor_init(sd->rx_pkt);
|
||||
|
||||
if (sd->recv_cb) {
|
||||
sd->recv_cb(sd->context,
|
||||
|
@ -793,7 +814,7 @@ static bool handle_socket_msg_recv(SOCKET sock,
|
|||
}
|
||||
|
||||
if (recv(sock, sd->pkt_buf->data,
|
||||
CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE, K_NO_WAIT)) {
|
||||
CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE, K_NO_WAIT)) {
|
||||
LOG_ERR("Could not receive packet in the buffer");
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue