Commit Graph

592 Commits

Author SHA1 Message Date
Damien George
e959f21986 extmod/vfs_fat: Update for new oofatfs version. 2019-03-05 15:56:39 +11:00
Damien George
9b2a97a903 extmod/modwebrepl: Fix logic to handle a put of file of size 0.
Fixes issue #4499.
2019-02-28 15:30:48 +11:00
Damien George
ed1a88e263 extmod/modlwip: Don't require a port to define concurrency macros. 2019-02-27 10:27:56 +11:00
Damien George
39ea132e1d extmod/modlwip: Add concurrency protection macros.
Some users of this module may require the LwIP stack to run at an elevated
priority, to protect against concurrency issues with processing done by the
underlying network interface.  Since LwIP doesn't provide such protection
it must be done here (the other option is to run LwIP in a separate thread,
and use thread protection mechanisms, but that is a more heavyweight
solution).
2019-02-26 23:32:19 +11:00
Damien George
42c0e440b9 extmod/modlwip: Fix bug when polling listening socket with backlog=1.
The bug polling for readability was: if alloc==0 and tcp.item==NULL then
the code would incorrectly check tcp.array[iget] which is an invalid
dereference when alloc==0.  This patch refactors the code to use a helper
function lwip_socket_incoming_array() to return the correct pointer for the
incomming connection array.

Fixes issue #4511.
2019-02-18 14:23:35 +11:00
Damien George
7ef9482b8a extmod/modlwip: Change #ifdef to #if for check of MICROPY_PY_LWIP.
Otherwise this code will be included if MICROPY_PY_LWIP is defined to 0.
2019-02-15 16:07:24 +11:00
Yonatan Goldschmidt
bc4f8b438b extmod/moduwebsocket: Refactor websocket to uwebsocket.
As mentioned in #4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
2019-02-14 00:35:45 +11:00
Damien George
f03601779e extmod: Convert legacy uppercase macro names to lowercase. 2019-02-12 14:54:51 +11:00
Yonatan Goldschmidt
f024b2610f extmod/moduhashlib: Include implementation of sha256 only when required.
Previously crypto-algorithms impl was included even if MICROPY_SSL_MBEDTLS
was in effect, thus we relied on the compiler/linker to cut out the unused
functions.
2019-02-07 23:27:58 +11:00
Paul Sokolovsky
2f5d113fad py/warning: Support categories for warnings.
Python defines warnings as belonging to categories, where category is a
warning type (descending from exception type). This is useful, as e.g.
allows to disable warnings selectively and provide user-defined warning
types.  So, implement this in MicroPython, except that categories are
represented just with strings.  However, enough hooks are left to implement
categories differently per-port (e.g. as types), without need to patch each
and every usage.
2019-01-31 16:48:30 +11:00
Damien George
2a7a307baa extmod/modlwip: Add support for polling UDP sockets for writability. 2019-01-31 11:22:03 +11:00
Paul Sokolovsky
c7ed17bc4b extmod/modussl_mbedtls: Remove deprecated mbedtls/net.h header include.
This header is deprecated as of mbedtls 2.8.0, as shipped with Ubuntu
18.04.  Leads to #warning which is promoted to error with uPy compile
options.

Note that the current version of mbedtls is 2.14 at the time of writing.
2019-01-27 12:26:09 +11:00
Paul Sokolovsky
35687a87ec extmod/moduzlib: Update for uzlib 2.9.2. 2019-01-27 10:59:49 +11:00
Paul Sokolovsky
b1cca8fbe0 extmod/uzlib: Update uzlib to v2.9.2.
Major changes include robust parsing of erroneous compressed streams and
updated API.
2019-01-27 10:59:30 +11:00
Damien George
7cd59c5bc3 py/mpconfig: Move MICROPY_VERSION macros to static ones in mpconfig.h.
It's more robust to have the version defined statically in a header file,
rather than dynamically generating it via git using a git tag.  In case
git doesn't exist, or a different source control tool is used, it's
important to still have the uPy version number available.
2018-12-22 01:40:38 +11:00
Paul Sokolovsky
38151f35c1 extmod/moductypes: Add aliases for native C types.
SHORT, INT, LONG, LONGLONG, and unsigned (U*) variants are being defined.
This is done at compile using GCC-style predefined macros like
__SIZEOF_INT__.  If the compiler doesn't have such defines, no such types
will be defined.
2018-12-10 14:40:43 +11:00
Paul Sokolovsky
9d864bde04 extmod/moductypes: Implement __int__ for PTR.
Allows to get address a pointer contains, as an integer.
2018-12-10 14:25:05 +11:00
Damien George
29da9f0670 extmod/modlwip: Fix read-polling of listening socket with a backlog.
The recent implementation of the listen backlog meant that the logic to
test for readability of such a socket changed, and this commit updates the
logic to work again.
2018-12-03 18:02:10 +11:00
Damien George
4737ff8054 extmod/modlwip: Implement TCP listen/accept backlog.
Array to hold waiting connections is in-place if backlog=1, else is a
dynamically allocated array.  Incoming connections are processed FIFO
style to maintain fairness.
2018-12-01 17:23:44 +11:00
Paul Sokolovsky
2411f42ccb extmod/moductypes: Make sizeof() accept "layout" parameter.
sizeof() can work in two ways: a) calculate size of already instantiated
structure ("sizeof variable") - in this case we already no layout; b) size
of structure decsription ("sizeof type"). In the latter case, LAYOUT_NATIVE
was assumed, but there should possibility to calculate size for other
layouts too. So, with this patch, there're now 2 forms:

uctypes.sizeof(struct)
uctypes.sizeof(struct_desc, layout)
2018-10-23 11:32:02 +11:00
Damien George
4904663748 extmod/modonewire: Fix reset timings to match 1-wire specs.
Fixes issue #4116.
2018-10-17 15:52:07 +11:00
Paul Sokolovsky
9fbd12f2fa extmod/moductypes: Accept OrderedDict as a structure description.
Using OrderedDict (i.e. stable order of fields) would for example allow to
automatically calculate field offsets in structures.
2018-10-13 16:08:12 +11:00
Paul Sokolovsky
18f45d2e23 extmod/moductypes: Remove BITFIELD from aggregate types enum.
This value is unused. It was an artifact of early draft design, but
bitfields were optimized to use scalar one-word encoding, to allow
compact encoding of typical multiple bitfields in MCU control
registers.
2018-10-05 17:02:15 +10:00
Damien George
05959c6465 extmod/moduhashlib: Add md5 implementation using mbedtls. 2018-09-12 16:08:53 +10:00
Damien George
87d45f4d49 extmod/moduhashlib: Use newer message digest API for mbedtls >=2.7.0.
Since mbedtls 2.7.0 new digest functions were introduced with a "_ret"
suffix to allow the functions to return an error message (eg, if the
underlying hardware acceleration failed).  These new functions must be used
instead of the old ones to prevent deprecation warnings, or link errors for
missing functions, depending on the mbedtls configuration.
2018-09-12 16:04:18 +10:00
Paul Sokolovsky
5fe3730a30 extmod/moduhashlib: Add md5 implementation, using axTLS.
MD5 is still widely used, and may be important in some cases for networking
interoperability, e.g. HTTP Digest authentication.
2018-09-11 14:51:52 +10:00
Damien George
0be2ea50e9 py/py.mk: Build axtls library directly from its source files.
This removes the need for a separate axtls build stage, and builds all
axtls object files along with other code.  This simplifies and cleans up
the build process, automatically builds axtls when needed, and puts the
axtls object files in the correct $(BUILD) location.

The MicroPython axtls configuration file is provided in
extmod/axtls-include/config.h
2018-09-08 00:07:23 +10:00
Damien George
206c65f22c extmod/modussl_axtls: Use MP_ROM_PTR for objects in allowed args array. 2018-08-14 21:47:07 +10:00
Damien George
b8b2525576 extmod/modbtree: Update to work with new mp_stream_posix_XXX signatures. 2018-08-14 17:41:23 +10:00
Damien George
7a67f057d7 extmod/modussl: Support polling in ussl objects by passing through ioctl
The underlying socket can handling polling, and any other transparent ioctl
requests.  Note that CPython handles the case of polling an ssl object by
polling the file descriptor of the underlying socket file, and that
behaviour is emulated here.
2018-07-20 13:05:04 +10:00
Damien George
4a2051eec7 extmod/modlwip: Deregister all lwIP callbacks when closing a socket.
Otherwise they may be called on a socket that no longer exists.

For example, if the GC calls the finaliser on the socket and then reuses
its heap memory, the "callback" entry of the old socket may contain invalid
data.  If lwIP then calls the TCP callback the code may try to call the
user callback object which is now invalid.  The lwIP callbacks must be
deregistered during the closing of the socket, before all the pcb pointers
are set to NULL.
2018-07-20 12:59:24 +10:00
Damien George
d974ee1c2f extmod/vfs_posix: Use DTTOIF if available to convert type in ilistdir. 2018-07-11 16:07:44 +10:00
Damien George
c700ff52a0 extmod/vfs_posix: Support ilistdir with no (or empty) argument. 2018-07-10 12:51:09 +10:00
Damien George
aa735dc6a4 extmod: Fix to support compiling with object representation D. 2018-07-08 23:15:44 +10:00
Damien George
a3c3dbd955 extmod/vfs: Support opening a file descriptor (int) with VfsPosix.
Fixes issue #3865.
2018-07-03 13:04:29 +10:00
Damien George
e30a5fc7bc extmod/modure: Add ure.sub() function and method, and tests.
This feature is controlled at compile time by MICROPY_PY_URE_SUB, disabled
by default.

Thanks to @dmazzella for the original patch for this feature; see #3770.
2018-07-02 14:55:02 +10:00
Damien George
1e9b871d29 extmod/modure: Add match.span(), start() and end() methods, and tests.
This feature is controlled at compile time by
MICROPY_PY_URE_MATCH_SPAN_START_END, disabled by default.

Thanks to @dmazzella for the original patch for this feature; see #3770.
2018-07-02 14:54:56 +10:00
Damien George
1f86460910 extmod/modure: Add match.groups() method, and tests.
This feature is controlled at compile time by MICROPY_PY_URE_MATCH_GROUPS,
disabled by default.

Thanks to @dmazzella for the original patch for this feature; see #3770.
2018-07-02 14:53:30 +10:00
Damien George
8769a3e38c extmod/moducryptolib: Don't include arpa/inet.h, it's not needed.
And some ports (eg esp8266) don't have it.
2018-06-27 16:44:59 +10:00
Yonatan Goldschmidt
31f2f1e967 extmod/moducryptolib: Shorten exception messages to reduce code size. 2018-06-27 16:44:59 +10:00
Yonatan Goldschmidt
d0507c084c extmod/moducryptolib: Prefix all Python methods/objects with ucryptolib.
Follows what was done in b045ebd35 for uhashlib.
2018-06-27 16:44:59 +10:00
Yonatan Goldschmidt
eacb233b8f extmod/moducryptolib: Add an mbedTLS implementation for this module. 2018-06-27 16:44:59 +10:00
Yonatan Goldschmidt
e328b4593c extmod/moducryptolib: Refactor functions for clean interface with axTLS.
This will allow implementations other than axTLS.

This commit includes additions of checks and clarifications of exceptions
related to user input.

To make the interface cleaner, I've disallowed switching from encrypt to
decrypt in the same object, as this is not always possible with other
crypto libraries (not all libraries have AES_convert_key like axTLS).
2018-06-27 16:44:59 +10:00
Yonatan Goldschmidt
473fe45da2 extmod/moducryptolib: Optionally export MODE_* constants to Python.
Allow including crypto consts based on compilation settings.  Disabled by
default to reduce code size; if one wants extra code readability, can
enable them.
2018-06-27 16:29:26 +10:00
Paul Sokolovsky
567bc2d6ce extmod/moducryptolib: Add ucryptolib module with crypto functions.
The API follows guidelines of https://www.python.org/dev/peps/pep-0272/,
but is optimized for code size, with the idea that full PEP 0272
compatibility can be added with a simple Python wrapper mode.

The naming of the module follows (u)hashlib pattern.

At the bare minimum, this module is expected to provide:

* AES128, ECB (i.e. "null") mode, encrypt only

Implementation in this commit is based on axTLS routines, and implements
following:

* AES 128 and 256
* ECB and CBC modes
* encrypt and decrypt
2018-06-27 14:54:40 +10:00
Damien George
e8398a5856 extmod: Update to use new mp_get_stream helper.
With this patch objects are only checked that they have the stream protocol
at the start of their use as a stream, and afterwards the efficient
mp_get_stream() helper is used to extract the stream protocol C methods.
2018-06-18 12:35:56 +10:00
Damien George
564abb01a5 extmod/vfs_fat_diskio: Factor disk ioctl code to reduce code size.
Functionality is unchanged.
2018-06-16 18:21:42 +10:00
Damien George
d11fb09333 extmod/modussl_axtls: Fix __del__ to point to mp_stream_close_obj. 2018-06-13 13:16:21 +10:00
Damien George
035906419d extmod/uos_dupterm: Use native C stream methods on dupterm object.
This patch changes dupterm to call the native C stream methods on the
connected stream objects, instead of calling the Python readinto/write
methods.  This is much more efficient for native stream objects like UART
and webrepl and doesn't require allocating a special dupterm array.

This change is a minor breaking change from the user's perspective because
dupterm no longer accepts pure user stream objects to duplicate on.  But
with the recent addition of uio.IOBase it is possible to still create such
classes just by inheriting from uio.IOBase, for example:

    import uio, uos

    class MyStream(uio.IOBase):
        def write(self, buf):
            # existing write implementation
        def readinto(self, buf):
            # existing readinto implementation

    uos.dupterm(MyStream())
2018-06-12 15:06:11 +10:00
Yonatan Goldschmidt
c2fb725e72 extmod/moduhashlib: Make function objects STATIC.
These are not exported to anyone anyway.
2018-06-12 13:50:11 +10:00