Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LwM2M 1.10 changes: LwM2M library use net_app API internally #1473

Merged
merged 10 commits into from
Sep 18, 2017

Conversation

mike-scott
Copy link
Contributor

This patchset moves the internals of the LwM2M library to the net_app API. To facilitate this we establish an lwm2m_context structure and use this to pass around various objects needed for app control. Also remove / cleanup fields which are now unused as a result.

Michael Scott added 2 commits September 12, 2017 14:56
The LwM2M library does not use net_app APIs internally.  To help
this effort let's establish a user facing structure "lwm2m_ctx"
(similar to http_client_ctx and mqtt_ctx) and start it off by
wrappering the net_context structure.

Future patches will add user setup options to this structure and
eventually remove the net_context structure in favor of a net_app_ctx.

Signed-off-by: Michael Scott <[email protected]>
@ghost ghost assigned mike-scott Sep 12, 2017
@ghost ghost added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Sep 12, 2017
@mike-scott mike-scott requested review from jukkar and removed request for jukkar September 12, 2017 22:17
@mike-scott
Copy link
Contributor Author

This is patchset #2 of 7 for 1.10 development window:

  1. Initial easy cleanup patches [done]
  2. move LwM2M library to use net_app APIs internally [current]
  3. introduce lwm2m_message structure to contain message data prior to CoAP serialization
  4. add lwm2m_message callback handlers for timeouts
  5. @rbtchc patchset to add push/pull support for firmware via firmware object
  6. Move LwM2M library to new CoAP APIs
  7. add DTLS support to LwM2M library and sample

@mike-scott
Copy link
Contributor Author

@rbtchc I can't add you as an official reviewer but please review and add comments / approval

@mike-scott mike-scott added the net label Sep 12, 2017
@mike-scott mike-scott added this to the v1.10 milestone Sep 12, 2017
client_ctx = CONTAINER_OF(obs->net_ctx,
struct lwm2m_ctx, net_ctx);
client_ctx = CONTAINER_OF(obs->net_app_ctx,
struct lwm2m_ctx, net_app_ctx);
if (!client_ctx) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think checking the client_ctx returned from CONTAINER_OF() macro is meaningless.
It always returns w/ the memory address deducted by the offset and is unlikely to be NULL.
If this makes sense to you, then we could remove the checking here and at other places.

if (memcmp(addr, &clients[i].reg_server,
app_ctx = &clients[i].ctx->net_app_ctx;
if (clients[i].ctx) {
if (memcmp(addr, &app_ctx->default_ctx->remote,
sizeof(addr)) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

sizeof(addr) -> sizeof(*addr)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixing.

@mike-scott
Copy link
Contributor Author

Fixed comment from @rbtchc diff: https://hastebin.com/vacogusewa.cpp

struct zoap_pending *pending;
int r;

pending = zoap_pending_next_to_expire(pendings, NUM_PENDINGS);
client_ctx = CONTAINER_OF(work, struct lwm2m_ctx, retransmit_work);
if (!client_ctx) {
Copy link
Collaborator

@rbtchc rbtchc Sep 14, 2017

Choose a reason for hiding this comment

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

Hi @mike-scott ,

I left two comments yesterday.
One probably folded because I left the comment on the outdated part of the code.

I check the macro "CONTAINER_OF", it's a simple offset deduction based on the given memory address. I suggest you can remove the check here for it's unlikely the address will be NULL.

if (!client_ctx) {
       ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixing.

Michael Scott added 6 commits September 14, 2017 09:10
This allows use to associate easily the replies / pending operations
with a specific network connection.

Signed-off-by: Michael Scott <[email protected]>
This is part of lwm2m_ctx and is not needed.

Signed-off-by: Michael Scott <[email protected]>
In preparation for the move to net_app APIs, we will need
to pass net_app_ctx structures around to the following
functions:
lwm2m_udp_sendto()
udp_request_handler()

Let's add the parameter as net_context for now so the
transition will be smoother later.

Signed-off-by: Michael Scott <[email protected]>
This is the final stage of moving the LwM2M library internals to
the net_app APIs.  This means we can support DTLS and other
built-in features in the future.  All of the logic for
establishing the network connection is removed from the sample
app.

Signed-off-by: Michael Scott <[email protected]>
Replace with a check of the state machine's state instead.

Signed-off-by: Michael Scott <[email protected]>
@mike-scott
Copy link
Contributor Author

Removed client_ctx check per @rbtchc recommendation. Diff: https://hastebin.com/ledubaxara.cpp

Copy link
Collaborator

@rbtchc rbtchc left a comment

Choose a reason for hiding this comment

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

LGTM

@mike-scott
Copy link
Contributor Author

Added @pfalcon purely for code review if he has time. No pressure.

app_ctx = &clients[i].ctx->net_app_ctx;
if (clients[i].ctx) {
if (memcmp(addr, &app_ctx->default_ctx->remote,
sizeof(*addr)) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just realize that in IPv6 case, the sockaddr in the app_ctx doesn't have the "sin6_scope_id" setup while "addr" does.
There's no match even if the packet is coming from the same peer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I am going to update this patch to use net_ipv4_addr_cmp() / net_ipv6_addr_cmp().

@mike-scott
Copy link
Contributor Author

As discussed, updated patch to use net_ipv6_addr_cmp() and net_ipv4_addr_cmp() in find_clients_index(). Diff: https://hastebin.com/eyihiliver.php

@rbtchc
Copy link
Collaborator

rbtchc commented Sep 15, 2017

Do we want to compare the port number as well?

@mike-scott
Copy link
Contributor Author

Bleh. You're right. These functions dont check port. I'll fix that tomorrow. Also, adding an initial check against sa_family != and remove the useless continue block at the end by making eack IP version check a stand alone if block.

Michael Scott added 2 commits September 15, 2017 09:47
All throughout the LwM2M library we use sockaddr values which are
basically the same as the net_app_ctx's remote addr.  There's no
reason to keep these extra sockaddr values around.  The net_app
framework client won't accept incoming requests on sockaddr other
than the one we're connected to.

Signed-off-by: Michael Scott <[email protected]>
This is the first part of a large refactoring of LwM2M library
message functions and will simplify observer handling later.

Signed-off-by: Michael Scott <[email protected]>
@mike-scott
Copy link
Contributor Author

Updated IP address checks as described (included port). diff: https://hastebin.com/ixatulital.php

@rbtchc
Copy link
Collaborator

rbtchc commented Sep 16, 2017

LGTM

@jukkar jukkar merged commit 70372f1 into zephyrproject-rtos:master Sep 18, 2017
@ghost ghost removed the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Sep 18, 2017
@mike-scott mike-scott deleted the lwm2m-net-app2 branch October 2, 2017 21:12
@nashif nashif modified the milestones: v1.10, v1.10.0 Oct 3, 2017
nagineni pushed a commit to nagineni/zephyr that referenced this pull request Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants