Commit Graph

191 Commits (c356f1f9d45a366fa1a89025e39b3aed54860db8)

Author SHA1 Message Date
Martin Kojtal bba527fdc2 Merge pull request #3457 from hasnainvirk/nsapi_connect
[ONME-2844] Supporting non-blocking connect()
2016-12-23 13:06:55 +00:00
Hasnain Virk fcd55fe65b [ONME-2844] Avoid option level collisions
To allow a network stack to support both NSAPI and its own options, try to make
sure the NSAPI levels don't collide with level numbers likely to be used by
network stacks.

Distinguish between socket and stack options, and tighten up documentation. Add
IP MRU stack options as an example (implementation not immediately planned for
any stack, but could be useful).
2016-12-20 14:03:23 +02:00
Hasnain Virk 35e4896ed3 [ONME-2844] Supporting non-blocking connect()
A few new error codes are added to nsapi_error_t and
support for non-blocking socket connect is added.
Nanostack's connect call will be non-blocking.
Whereas LWIP connect call is currently blocking, and it could be changed now
to be non-blocking.
2016-12-16 15:35:33 +02:00
Christopher Haster 3643b59109 nsapi - Fixed open/close issue in Socket
During open, the socket checked the internal stack variable,
assuming it would alway be null on a socket not connected to
the network. However, when a socket is closed, the stack variable
was not updated, causing the socket to incorrectly return a
parameter error if reopened.

The simple fix was to set the stack to null on close. A non-null
stack is a predicate for a non-null socket variable, so no additional
checks are needed in socket functions.
2016-12-08 16:14:15 -06:00
Bogdan Marinescu 337c1af22c Don't send events on close()
It's currently possible to generate a socket event when a non-blocking socket is closed:

1. _pending is set to 0 in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.cpp#L22
   when the socket is created.
2. close() calls event() in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/Socket.cpp#L66
3. event() increments _pending, and since _pending is 1 it will call _callback() in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.cpp#L167

However, if send() (for example) is called, this can happen:

- send() is called and sets _pending to 0.
- when the data is sent, event() is called, which sets _pending to 1 and calls _callback().
- if close() is called at this point, there won't be an event generated for close() anymore,
  since _pending will be set to 2.

Same thing for recv. Also, same thing for TCPServer and UDPSocket.

This PR changes the initial value of _pending to 1 instead of 0, so that
events are never generated for close().
2016-12-07 17:52:16 +02:00
Martin Kojtal 98029e3906 Merge pull request #3065 from geky/nsapi-remove-same-thread-asserts
nsapi - Remove assertions on same-thread send/recv
2016-11-16 17:41:13 +00:00
Anna Bridge 405f8937a7 Merge pull request #3191 from tung7970/fix-mbedos
Fix lwip_mac_address buffer overflow and set_ip_bytes out of bound access
2016-11-10 17:05:38 +00:00
Anna Bridge 5fd81b37c3 Merge pull request #3232 from geky/nsapi-fix-gethostbyname-unspec-literal
nsapi - Fix missing NSAPI_UNSPEC check in gethostbyname for ip literals
2016-11-10 16:54:27 +00:00
Bartek Szatkowski db15c1a0a3 WiFi: Minor fixes to docs and includes 2016-11-10 09:40:48 +00:00
Christopher Haster a3ad6181f4 nsapi - Fixed missing NSAPI_UNSPEC check in gethostbyname for ip literals 2016-11-08 18:05:35 -06:00
Martin Kojtal 96e1d5bd73 Merge pull request #3221 from andreaslarssonublox/ublox_odin_w2_drivers_update
u-blox odin w2 drivers update
2016-11-08 10:24:53 +00:00
Sam Grove 074555b715 Merge pull request #3113 from geky/static-assert
Add static assert macro
2016-11-07 10:25:17 -06:00
Christopher Haster 40836b11a5 nsapi - Removed assertions on same-thread send/recv
Initially these assertions were added to protected simultaneous
send/recv from the same socket when similarly purposed mutexes were
removed.

However, simultaneous send/recv can still be useful for UDP if the
payload is guaranteed to be less than the MTU across the entire
connection.
2016-11-07 09:43:09 -06:00
andreas.larsson e111810830 Added emac_stack_mem_copy. Needed by the u-blox ODIN-W2 driver. 2016-11-07 15:52:56 +01:00
Martin Kojtal 7eaf32baa0 Merge pull request #3075 from geky/nsapi-error-size-types-2
nsapi - Add standardized return types for size and errors
2016-11-07 11:13:40 +00:00
Tony Wu 70ad0f5226 netsocket - Fix set_ip_bytes out-of-bound access
set_ip_bytes() does a 16-byte memcpy from the input buffer to
the local nsapi_addr_t despite the address version.

If the address version is ipv4, the input buffer may only be
4-byte in size. This causes a out-of-bound access on the input buffer.

Signed-off-by: Tony Wu <tonywu@realtek.com>
2016-11-04 11:02:34 +08:00
Sam Grove 35dbb3f256 Merge pull request #3166 from kjbracey-arm/ipv6_dns_server
nsapi_dns: Provide 2 IPv6-hosted default servers
2016-11-03 02:17:52 -05:00
Christopher Haster ba748ac1f8 nsapi - Added standardized return types for size and errors
nsapi_error_t         - enum of errors or 0 for NSAPI_ERROR_OK
nsapi_size_t          - unsigned size of data that could be sent
nsapi_size_or_error_t - either a non-negative size or negative error
2016-11-02 15:25:22 -05:00
Christopher Haster 98db3ab1cb Adopted MBED_STATIC_ASSERT where possible 2016-11-01 21:39:48 -05:00
Sam Grove 7829b2f9bf Merge pull request #3161 from geky/nsapi-dns-version-heuristic
nsapi - Add better heuristic for the default record of DNS queries
2016-11-01 14:17:08 -05:00
Kevin Bracey aa583bd8ce nsapi_dns: Provide 2 IPv6-hosted default servers
Replace Comodo and OpenDNS IPv4 servers with Google and DNS.WATCH IPv6
servers, so IPv6-only devices (eg 6LoWPAN) have a default.

3 IPv4 resolvers should be plenty - existing code doesn't remember which
one last worked, so if early list entries were unreachable performance
would be consistently bad anyway. Replacing two entries avoids
increasing image size and RAM consumption.

On an IPv6-only or IPv4-only system, the sendto() for the wrong type of
address should fail immediately - change loop to move on to the next
server for any sendto() error.
2016-10-31 15:48:54 +02:00
Christopher Haster 42105371ef lwip/nsapi - Cleaned up warnings in network code
- cc.h@57,1: "BYTE_ORDER" redefined
- lwip_inet_chksum.c@560,44: passing argument 1 of 'thumb2_checksum'
  discards 'const' qualifier from pointer target type
- lwip_pbuf.c@1172,9: variable 'err' set but not used
- SocketAddress.cpp@293,1: control reaches end of non-void function
2016-10-28 14:24:52 -05:00
Christopher Haster d8d2b0a41d nsapi - Added better heuristic for the default record of DNS queries
Takes advantage of the get_ip_address function to predict the IP
address version wanted by the underlying interface. The should avoid
the need for most IPv6 interfaces to overload gethostbyname.

suggested by @kjbracey-arm
2016-10-28 11:41:33 -05:00
Martin Kojtal ba47aa546b Merge pull request #2897 from geky/nsapi-consistent-unspec
nsapi - Standardize support of NSAPI_UNSPEC
2016-10-27 10:26:00 +02:00
Christopher Haster cce82b13ac nsapi - Fixed unaligned writes from <word-sized scanf calls 2016-10-19 16:49:35 -05:00
Christopher Haster bf83cb28cd nsapi - Fixed leftover bytes from suffix during ipv6 parsing
Thanks to @EduardPon for hunting this down
2016-10-19 15:28:32 -05:00
Sam Grove 44dcb5f21f Merge pull request #2994 from 0xc0170/fix_issue#2993
lwip-interface: fix issue #2993
2016-10-13 11:14:10 -05:00
Martin Kojtal f8b682c943 lwip-interface: fix issue #2993
DEVICE_ are passed as command line -D, thus no inclusion is required.
``platform.h`` is C++ header file, should not be pulled in C files
2016-10-13 11:42:31 +01:00
Bartek Szatkowski 3d09b196b7 DNS: Rework DNS query
Don't ask multiple DNS servers in case of successful connection, even if
the response is negative. Make sure the return value is correct.
2016-10-11 10:53:05 -05:00
Bartek Szatkowski 922e9526bf DNS: Fix return value for successful name resolutions 2016-10-07 16:10:15 +01:00
Sam Grove 3a16ca9855 Merge pull request #2911 from theotherjimmy/docs-generation
[Tools] Add documentation generation script
2016-10-06 15:57:08 -05:00
Christopher Haster 1f4eb0aaa1 nsapi - Standardized support of NSAPI_UNSPEC
- Reordered nsapi_version_t to make defaule nsapi_addr_t NSAPI_UNSPEC
- Added support to NSAPI_UNSPEC in SocketAddress
2016-10-05 12:48:10 -05:00
Jimmy Brisson f1a78027d3 Add tags to our code 2016-10-04 15:02:44 -05:00
Christopher Haster 4f1ededb58 Renamed NSAPI_SECURITY_UNSUPPORTED -> NSAPI_SECURITY_UNKNOWN
Returning a wifi access point without information regarding the
security type is only valid if the security type is unknown (from
the perspective of the network-socket API). For clarity in situations
in which scan may return an unsupported, but known security type,
type name has been changed to NSAPI_SECURITY_UNKNOWN.
2016-10-04 14:23:36 -05:00
Bartek Szatkowski febc341672 Fix spelling error: NSAPI_SECURITY_UNSUPPORTED 2016-10-04 17:34:58 +01:00
andreas.larsson e87f013c4d Fixed missing public 2016-10-04 15:52:56 +02:00
andreas.larsson 8ea46eae17 Fixed missing abstract connect method 2016-10-04 15:52:55 +02:00
andreas.larsson b418fce8ac Added function for increasing ref count. 2016-10-04 15:52:55 +02:00
Christopher Haster 5cd2d7869e Merge remote-tracking branch 'upstream/master' into feature_wifi_ublox_merge 2016-10-02 07:29:07 -05:00
Christopher Haster c2d9fc29ff restructure - Fixed include paths damaged by the restructure 2016-09-30 19:18:09 -05:00
Christopher Haster ba99a1f31d restructure - Restructured features/net directory
features/net/network-socket -> features/netsocket
features/net/FEATURE_IPV4 -> features/FEATURE_LWIP
features/net/nanostack-binaries -> features/nanostack
features/net/FEATURE_NANOSTACK -> features/nanostack/FEATURE_NANOSTACK
2016-09-30 19:18:09 -05:00