Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/net/http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
extern "C" {
#endif

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
/* Also update SONAME in the Makefile whenever you change these. */
#define HTTP_PARSER_VERSION_MAJOR 2
#define HTTP_PARSER_VERSION_MINOR 7
#define HTTP_PARSER_VERSION_PATCH 1
#endif

#include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__) && \
Expand All @@ -47,6 +49,7 @@ typedef unsigned __int64 u64_t;
#include <stddef.h>
#endif

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
/* Maximium header size allowed. If the macro is not defined
* before including this header then the default is used. To
* change the maximum header size, define the macro in the build
Expand Down Expand Up @@ -227,6 +230,7 @@ struct http_parser_settings {
http_cb on_chunk_header;
http_cb on_chunk_complete;
};
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */


enum http_parser_url_fields {
Expand Down Expand Up @@ -261,6 +265,7 @@ struct http_parser_url {
};


#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
/* Returns the library version. Bits 16-23 contain the major version number,
* bits 8-15 the minor version number and bits 0-7 the patch level.
* Usage example:
Expand Down Expand Up @@ -305,6 +310,7 @@ const char *http_errno_name(enum http_errno err);

/* Return a string description of the given error */
const char *http_errno_description(enum http_errno err);
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */

/* Initialize all http_parser_url members to 0 */
void http_parser_url_init(struct http_parser_url *u);
Expand All @@ -313,11 +319,13 @@ void http_parser_url_init(struct http_parser_url *u);
int http_parser_parse_url(const char *buf, size_t buflen,
int is_connect, struct http_parser_url *u);

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
/* Pause or un-pause the parser; a nonzero value pauses */
void http_parser_pause(struct http_parser *parser, int paused);

/* Checks if this is the final chunk of the body. */
int http_body_is_final(const struct http_parser *parser);
#endif

#ifdef __cplusplus
}
Expand Down
7 changes: 6 additions & 1 deletion include/net/lwm2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ int lwm2m_device_add_err(u8_t error_code);
#define RESULT_UPDATE_FAILED 8
#define RESULT_UNSUP_PROTO 9

#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT)
void lwm2m_firmware_set_write_cb(lwm2m_engine_set_data_cb_t cb);
lwm2m_engine_set_data_cb_t lwm2m_firmware_get_write_cb(void);

#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT)
void lwm2m_firmware_set_update_cb(lwm2m_engine_exec_cb_t cb);
lwm2m_engine_exec_cb_t lwm2m_firmware_get_update_cb(void);
#endif
#endif

/* LWM2M Engine */

Expand Down Expand Up @@ -156,5 +162,4 @@ int lwm2m_engine_start(struct net_context *net_ctx);
int lwm2m_rd_client_start(struct net_context *net_ctx,
struct sockaddr *peer_addr,
const char *ep_name);

#endif /* __LWM2M_H__ */
20 changes: 17 additions & 3 deletions samples/net/lwm2m_client/src/lwm2m-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,23 @@ static int device_factory_default_cb(u16_t obj_inst_id)
return 1;
}

#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT)
static int firmware_update_cb(u16_t obj_inst_id)
{
SYS_LOG_DBG("UPDATE");

/* TODO: kick off update process */

/* If success, set the update result as RESULT_SUCCESS.
* In reality, it should be set at function lwm2m_setup()
*/
lwm2m_engine_set_u8("5/0/3", STATE_IDLE);
lwm2m_engine_set_u8("5/0/5", RESULT_SUCCESS);
return 1;
}
#endif

#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT)
static int firmware_block_received_cb(u16_t obj_inst_id,
u8_t *data, u16_t data_len,
bool last_block, size_t total_size)
Expand All @@ -174,6 +185,7 @@ static int firmware_block_received_cb(u16_t obj_inst_id,
data_len, last_block);
return 1;
}
#endif

static int set_endpoint_name(char *ep_name, sa_family_t family)
{
Expand Down Expand Up @@ -232,10 +244,12 @@ static int lwm2m_setup(void)

/* setup FIRMWARE object */

lwm2m_engine_register_post_write_callback("5/0/0",
firmware_block_received_cb);
#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT)
lwm2m_firmware_set_write_cb(firmware_block_received_cb);
lwm2m_engine_register_exec_callback("5/0/2", firmware_update_cb);
#endif
#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT)
lwm2m_firmware_set_update_cb(firmware_update_cb);
#endif

/* setup TEMP SENSOR object */

Expand Down
7 changes: 7 additions & 0 deletions subsys/net/lib/http/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ config HTTP_PARSER
This parser requires some string-related routines commonly
provided by a libc implementation.

config HTTP_PARSER_URL_ONLY
bool "HTTP URL parser only support"
default n
select HTTP_PARSER
help
This option only enables URL parser of the http_parser library.

config HTTP_PARSER_STRICT
bool "HTTP strict parsing"
default n
Expand Down
12 changes: 12 additions & 0 deletions subsys/net/lib/http/http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ do { \
} \
} while (0)

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
/* Don't allow the total size of the HTTP headers (including the status
* line) to exceed HTTP_MAX_HEADER_SIZE. This check is here to protect
* embedders against denial-of-service attacks where the attacker feeds
Expand Down Expand Up @@ -169,6 +170,7 @@ s8_t unhex[256] = {
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */


#ifdef HTTP_PARSER_STRICT
Expand Down Expand Up @@ -284,6 +286,7 @@ enum state {
s_message_done
};

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
#define PARSING_HEADER(state) (state <= s_headers_done)

enum header_states {
Expand Down Expand Up @@ -311,6 +314,7 @@ enum header_states {
h_connection_close,
h_connection_upgrade
};
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */

enum http_host_state {
s_http_host_dead = 1,
Expand All @@ -327,6 +331,7 @@ enum http_host_state {
s_http_host_port
};

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
static inline
int cb_notify(struct http_parser *parser, enum state *current_state, http_cb cb,
int cb_error, size_t *parsed, size_t already_parsed)
Expand Down Expand Up @@ -382,6 +387,7 @@ int cb_data(struct http_parser *parser, http_data_cb cb, int cb_error,

return 0;
}
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */


/* Macros for character classes; depends on strict-mode */
Expand Down Expand Up @@ -416,6 +422,7 @@ int cb_data(struct http_parser *parser, http_data_cb cb, int cb_error,
(IS_ALPHANUM(c) || (c) == '.' || (c) == '-' || (c) == '_')
#endif

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
/**
* Verify that a char is a valid visible (printable) US-ASCII
* character or %x80-FF
Expand Down Expand Up @@ -493,6 +500,7 @@ static struct {
};

int http_message_needs_eof(const struct http_parser *parser);
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */

/* Our URL parser.
*
Expand Down Expand Up @@ -655,6 +663,7 @@ static enum state parse_url_char(enum state s, const char ch)
return s_dead;
}

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
static
int parser_header_state(struct http_parser *parser, char ch, char c)
{
Expand Down Expand Up @@ -2624,6 +2633,7 @@ const char *http_errno_description(enum http_errno err)

return http_strerror_tab[err].description;
}
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */

static enum http_host_state
http_parse_host_char(enum http_host_state s, const char ch)
Expand Down Expand Up @@ -2906,6 +2916,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
return 0;
}

#if !defined(CONFIG_HTTP_PARSER_URL_ONLY)
void http_parser_pause(struct http_parser *parser, int paused)
{
/* Users should only be pausing/unpausing a parser that is not in an
Expand Down Expand Up @@ -2933,3 +2944,4 @@ unsigned long http_parser_version(void)
HTTP_PARSER_VERSION_MINOR * 0x00100 |
HTTP_PARSER_VERSION_PATCH * 0x00001;
}
#endif /* !CONFIG_HTTP_PARSER_URL_ONLY */
15 changes: 11 additions & 4 deletions subsys/net/lib/lwm2m/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,29 @@ config LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
bool "Firmware Update object pull support"
default y
depends on LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT
select HTTP_PARSER_URL_ONLY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add "select HTTP_PARSER" here too as when doing "select" in Kconfig, it will not recursively select other options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about my comment here, is the HTTP_PARSER option selected by some other way? What I mean by this is if you select HTTP_PARSER_URL_ONLY here, it will not select HTTP_PARSER automatically (at least that is how Kconfig worked before) i.e., recursive "select" is not implemented. But it might be that the HTTP_PARSER is selected automatically by some other mean in which case my concern is moot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add "select HTTP_PARSER" at subsys/net/lib/http/Kconfig#L68 when config HTTP_PARSER_URL_ONLY is selected.
In this way, when LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT is selected, both HTTP_PARSER & HTTP_PARSER_URL_ONLY will be selected as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I missed that.

help
Include support for pulling a file from a remote server via
block transfer and "FIRMWARE PACKAGE URI" resource. This option
adds another UDP context and packet handling.

config LWM2M_FIRMWARE_UPDATE_PULL_COAP_BLOCK_SIZE
int "Firmware Update object pull CoAP block size"
depends on LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
config LWM2M_COAP_BLOCK_SIZE
int "LWM2M CoAP block-wise transfer size"
default 256
default 64 if NET_L2_BT
default 64 if NET_L2_IEEE802154
range 16 1024
help
CoAP block size used by firmware pull when performing block-wise
CoAP block size used by LWM2M when performing block-wise
transfers. Possible values: 16, 32, 64, 128, 256, 512 and 1024.

config LWM2M_NUM_BLOCK1_CONTEXT
int "Maximum # of LWM2M block1 contexts"
default 3
help
This value sets up the maximum number of block1 contexts for
CoAP block-wise transfer we can handle at the same time.

config LWM2M_RW_JSON_SUPPORT
bool "support for JSON writer"
default y
Expand Down
Loading