Commit graph

12 commits

Author SHA1 Message Date
Adam Porter 9da0f2af31 drivers: modem: use zsock_ variants of socket API
By using the Zephyr-native zsock_ family of types and functions, these
drivers will be decoupled from NET_SOCKETS_POSIX_NAMES.

Signed-off-by: Adam Porter <porter.adam@gmail.com>
2020-06-10 09:27:51 +03:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Peter Bigot 93884a4fe1 coccinelle: run int_ms_to_timeout conversion semantic patch
This fixes some cases where an integer timeout received as a parameter
was not converted to a timeout before being used in standard API.

Changes to the POSIX library were not included as that's being
reworked in a separate PR.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-07 19:46:03 +02:00
Michael Scott 889fc85f67 drivers: modem: socket: add is_connected field to modem_socket
Let's add a field which the drivers can use to keep track of whether
they are connected or not.  This will normally be enabled / disabled
in the socket connect and URC for socket close notify.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 25ce3bf3eb drivers: modem: socket: add modem_socket_next_packet_size
Let's hide the internals of sock->packet_sizes[] by adding a function
which returns the size of the next waiting packet.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott e23ada9d4a drivers: modem: socket: reset is_polled in modem_socket_put()
Let's make sure is_polled gets reset when we reset the socket.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 8908c61bcc drivers: modem: socket: add wait_data and data_ready functions
Let's hide the internals of the modem_socket's sem_data_ready and
poll handling with 2 new functions:
- modem_socket_wait_data: take a semaphore and wait for data
- modem_socket_data_ready: give back the data ready semaphore and
  unblock poll() users

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 987837ecd8 drivers: modem: socket: introduce locking
Add lock behavior for functions in modem_socket, to prevent race
conditions when performing socket data maintenance.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott d4b8b5fcf2 drivers: modem: socket: allow partial packet reads
Let's allow protocols to request portions of the current packet.

This is seen in the MQTT library when parsing headers for the type
and variable length of the packet.

This fixes basic parsing done in the MQTT library and probably others.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Robert Lubos e434725bdf drivers: modem: ublox-sara-r4: Rework offloading mechanism
Switch to `NET_SOCKET_REGISTER` mechanism over the offloaded API
registration.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 11:36:02 -05:00
Michael Scott a7379234ba drivers: modem: socket: sock_fd isn't an index in modem_socket_put()
modem_socket_put() originally took an index as a parameter and was
later swapped to sock_fd as the reference.

The internal code was never updated to reflect that sock_fd isn't an
index -- it's a separate reference generated via z_reserve_fd().

Let's correct the modem_socket_put() logic.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18238

Reported-by: Tobias Svehagen <tobias.svehagen@gmail.com>
Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-14 11:01:47 +02:00
Michael Scott f5c45c2946 drivers: modem: introduce socket helper layer
Many modems implement socket-based APIs to manage data connections.
This layer provides much of the groundwork for keeping track of
these "sockets" throughout their lifecycle (from the initial offload
API calls through the command handler call back layers):
- structure for holding socket data like IP protocol, destination,
  source and incoming packet sizes
- configuration to note modem starting socket id and number of
  sockets
- methods to get/put socket structs from/to the pool
- function to update the # and size of packets in the modem receive
  queue
- prebuilt modem_socket_poll() method for socket offload poll() API

Example modem driver setup code looks like this:

/* socket data */
static struct modem_socket_config socket_config;
static struct modem_socket sockets[MDM_MAX_SOCKETS];

static int modem_init(struct device *dev)
{
  ...
  /* setup socket config */
  socket_config.sockets = &sockets[0];
  socket_config.sockets_len = ARRAY_SIZE(sockets);
  socket_config.base_socket_num = 0;
  ret = modem_socket_init(&socket_config);
  ...
}

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-10 00:03:39 +02:00