By changing the various *NET_DEVICE* macros. It is up to the device
drivers to either set a proper PM function or, if not supported or PM
disabled, to use device_pm_control_nop relevantly.
All existing macro calls are updated. Since no PM support was added so
far, device_pm_control_nop is used as the default everywhere.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Source and destination ports should be set properly
when assembling the receive socket data.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Some commands need to be processed before a "\r\n" is available and
there might also be commands that have "\r\n" as data but doesn't mean
the end of the command.
To solve this a MODEM_CMD_DIRECT has been added. cmd_handler_process()
will look for matching direct commands before checking if a whole line
is available for matching the normal commands.
A direct command can return either -EAGAIN, meaning that more data is
needed or it will return the number of bytes to skip forward, ie the
length of the command that was handled.
Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
User is currently able to enable verbose packet debugging for
received packets. This commit enables the same for sent packets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
pin is an unsigned variable so there is no meaning check if it is less
than zero.
CID :208407
CID :208408
CID :208410
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
usage of AT+UPSD command per UBX-17003787(R15) command reference is:
AT+UPSD=<profile_id>, <param_tag>, <param_val>
For AT+UPSD=0, 1, "<value>": we are setting value to MCCMNO, which
is technically incorrect. <param_tag> of 1 means:
1: APN - <param_val> defines the APN text string, e.g.
"apn.provider.com"; the maximum length is 99. The factory-programmed
value is an empty string.
Let's use APN here instead. This fixes a +CME ERROR: 113 when
connecting with U2 modem.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/22689
Signed-off-by: Michael Scott <mike@foundries.io>
Add Kconfig option that allows user to set MCC (Mobile Country
Code). If user does not set it, then automatic operator
registration is used.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Misc fixes / enhancements to the GSM driver:
* set the \r as a line ending character
* make gsm_init() static as there is no need to expose it
* print the gsm context pointer at init
* set buffer allocation timeout to modem context so that it is
not infinite
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of using global static variable "gsm" everywhere,
store the context when calling DEVICE_INIT(). Then in the device
init function get the context from the device struct. This way
it is possible to use the same functions for implementing two
gsm modem instances. Currently this is not fully possible because
the context is not passed via uart_pipe API and modem_cmd
callbacks. So some future work would still be needed.
In practice this commit does not change anything, it just makes
it a little bit easier to have two instance of this modem which
might be quite unlikely case. Anyway, the driver now follows the
same style how some other drivers are done like Ethernet etc.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Now that the u-blox driver can let cmd_handler know that it hasn't
received enough data, let's disable the hex mode for readying
binary data.
On the SARA-R4 this mode limits the receiving MTU to 512 which is
unacceptable.
Signed-off-by: Michael Scott <mike@foundries.io>
Some modem commands can determine if they have enough data pulled from
the modem to continue or not. Let's allow those functions to return
EAGAIN which means there's more data needed from the modem.
Signed-off-by: Michael Scott <mike@foundries.io>
Modem commands are setup with arg_count to denote the number of params
to parse before returning. Let's honor that setting and return once
we've parse them.
This fixes a run-on bug where the parser would find as many of the
parameters via the supplied delimiter as it could.
Signed-off-by: Michael Scott <mike@foundries.io>
The original Ublox SARA-R4 driver was written for the net_context
APIs. As a result many of the return values are not POSIX standard.
Let's go through all of the socket offload functions and make sure
we return standard values (0 or -1) and set errno where appropriate.
Signed-off-by: Michael Scott <mike@foundries.io>
SARA-R4 has a max read limit of 512 when using binary hex formatting.
Otherwise the max read limit is 1024.
Signed-off-by: Michael Scott <mike@foundries.io>
New socket functions were introduced to hide some of the modem_socket
internals:
- modem_socket_next_packet_size()
- modem_socket_wait_data()
- modem_socket_data_ready()
Let's use them.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's use sock->is_connected to check whether we need to clean up
the modem's socket. It may have already been closed via URC.
Signed-off-by: Michael Scott <mike@foundries.io>
SARA-R4 AT command manual states +USOCO has a max timeout of 120s.
Let's use that instead of the default 10s command timeout.
Signed-off-by: Michael Scott <mike@foundries.io>
The SARA R412M requires manual activation of the PDP context. It also
reports RSSI instead of RSRP when on 2G. An off-by-one in the RSRP
calculation was also fixed in this commit.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
The u-blox SARA modems have the ability to output the network status
on a GPIO pin. This can be used to light up a LED when the modem is
connected to the network.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
The U2 modem will sometimes not power off even if we have given it the
signal to do so. We now signal it continually until the modem
indicates that power is off with VINT=0.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
This fixes two problems in modem_reset():
- mdata.net_iface is used without checking that it is valid.
Now, we validate mdata_net_iface before usage, and give a warning
if it was not set.
- if the modem does not perform network registration within the
given time of 20s, in the previous implementation the driver
gave up.
Now, the driver disables RF for a second, enables it again and
gives the modem another 20s to register. This has been seen
to help in roaming situations.
Tested on Sara R4.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
- limit max. number of bytes when sending to socket
The number of bytes sent to a socket in one transaction
is limited to 512 in HEX mode (Sara-R4), and to 1024
otherwise. This corresponds to numbers given in the
manual for ublox cellular modems.
- report number of bytes actually sent, as reported by modem
After writing data to a socket, we now return the number of
bytes actually written, as reported by the modem.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
In order to still process 128 bytes at a time, let's add 1 to the
length of match_buf which will be used to store a NUL char when
the match_buf is at max size (size - 1).
Otherwise we're processing 127 bytes at a time which is inefficient
compared to the data buffer sizes in net_buf.
Signed-off-by: Michael Scott <mike@foundries.io>
SARA-R4 modem supports offloaded DNS via AT+UDNSRN command.
Let's implement it.
NOTE! On SARA-R4 a new firmware *IS* required to support this feature:
L0.0.00.00.05.08 [Apr 17 2019 19:34:02]
Signed-off-by: Michael Scott <mike@foundries.io>
Managing the interface up / down events from driver code (as opposed
to L2 layers) has been an issue for quite some time. There are
race conditions which result in data aborts (referencing NULL
iface or NULL iface->if_dev) or ends up breaking ASSERT checks for
non-NULL iface.
Let's remove the handling for now and come up with something better
when a user actually needs it.
Signed-off-by: Michael Scott <mike@foundries.io>
In offload_recvfrom(), if we end up calling modem_cmd_send(),
then we should always wait for the results. We've already
checked for MSG_DONTWAIT and made sure that there is data ready.
We just need to get it from the modem buffer at this point.
Signed-off-by: Michael Scott <mike@foundries.io>
Users may be waiting for data via socket recv() function. We
notify them that data is ready when URC is received from modem.
Once unblocked, we read the data from the modem buffer which
is handled via on_cmd_sockread_common(). At this point, we
don't need to unblock waiting users again.
Signed-off-by: Michael Scott <mike@foundries.io>
The hex_to_binary() function is incorrectly assuming all buffers
passed to recv() will have an additinal byte for storing a NUL
terminating char. This should be optional as MQTT library uses
exact sized buffers for parsing socket data.
Signed-off-by: Michael Scott <mike@foundries.io>
The send_socket_data() is incorrectly sending 0 as successful result.
The socket APIs require the number of bytes sent to be returned.
Signed-off-by: Michael Scott <mike@foundries.io>
For parsing purposes we need to add a NUL to the end of match_buf.
When there is no CR/LF in the incoming rx bufs then we fill match_buf
to its max size. This ended up with an off by one error which was
overflowing match_buf into the following data.
To account for this, let's fill the buffer to size - 1 so that we
leave room for the NUL at the end and stop corrupting data.
Signed-off-by: Michael Scott <mike@foundries.io>
- rename buf_len to match_len for clarity
- pass in modem_cmd_handler_data instead of buffer pointer directly
- buffer adjustments for the command length are kept inside
parse_params()
Signed-off-by: Michael Scott <mike@foundries.io>
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>
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>
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>
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>
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>
Compile errors because of missing include file and typos
when accessing variables in the modem_pin struct.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
After startup ublox-sara-r4 code sets the MDM_POWER signal to input
using a deprecated configuration macro. This was the only use of the
modem context API to configure a pin.
Refactor the API to not take the flags as an input but instead select
between the flags to be used when the pin is active and a disconnected
state. Use this API instead of a separate direct configure call when
initializing the modem pins.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Conver to the new GPIO API using raw access, since the driver
has its own macros to define signal levels.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Convert to the new API using raw access, since it's a common access
layer shared by multiple (right now only ublox-sara-r4) modems.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>