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

Support AWS IoT #146

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Support AWS IoT #146

wants to merge 11 commits into from

Conversation

happyRip
Copy link
Member

@happyRip happyRip commented Nov 14, 2024

Summary

Closes #143

Changes

Main:
  • Add awsiot source
Other:
  • Rename all source command variables to Command.
    • e.g. awsiot.Command instead of awsiot.AWSIoTCmd
  • Define util.Unmarshaller interface that was not defined previously.

Testing

Tested by migrating a device from AWSIoT to TTS using Arduino MKR WAN 1310.

$ go run ./cmd/ttn-lw-migrate awsiot device f198fd57-e52d-49fd-bcec-5b5494748469 > arduino_otaa.json

arduino_otaa.json

$ go run ./cmd/ttn-lw-migrate awsiot device c5b08612-af8b-41cf-80fa-da3d861ed81c > arduino_abp.json

arduino_abp.json

$ go run ./cmd/ttn-lw-migrate awsiot device < devices.txt > devices.json

devices.txt
devices.json

Screenshot 2025-02-12 at 20 03 24 Screenshot 2025-02-12 at 20 22 40 Screenshot 2025-02-12 at 20 24 17
Regressions

...

Notes for Reviewers

Checklist

  • Scope: The referenced issue is addressed, there are no unrelated changes.
  • Documentation: Relevant documentation is added or updated.
  • Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.

@happyRip happyRip added this to the Nov 2024 milestone Nov 14, 2024
@happyRip happyRip self-assigned this Nov 14, 2024
@happyRip happyRip force-pushed the feature/aws-iot branch 3 times, most recently from 628b361 to 7786d85 Compare November 14, 2024 09:37
@happyRip happyRip requested a review from KrishnaIyer November 14, 2024 09:43
@happyRip happyRip marked this pull request as ready for review November 14, 2024 09:43
@happyRip happyRip force-pushed the feature/aws-iot branch 3 times, most recently from ba6e5ba to 4ca8a42 Compare November 14, 2024 09:51
Copy link
Member

@johanstokking johanstokking left a comment

Choose a reason for hiding this comment

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

LGTM

@KrishnaIyer KrishnaIyer modified the milestones: Nov 2024, Dec 2024 Dec 2, 2024
@KrishnaIyer KrishnaIyer modified the milestones: Dec 2024, Jan 2025 Jan 13, 2025
@KrishnaIyer KrishnaIyer modified the milestones: Jan 2025, Feb 2025 Jan 29, 2025
@happyRip happyRip assigned halimi and unassigned happyRip Feb 12, 2025
@halimi
Copy link

halimi commented Feb 12, 2025

@KrishnaIyer @happyRip it is ready for review.

README.md Outdated
```bash
$ export APP_ID="my-app" # Application ID for the exported devices
$ export FREQUENCY_PLAN_ID="EU_863_870" # Frequency Plan ID for the exported devices
$ export NO_SESSION="true" # Export devices without session
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note to set this based on the requirement.

}

type abpKeys struct {
appSKey, fNwkSIntKey, nwkSKey, sNwkSIntKey, devAddr *string
Copy link
Member

Choose a reason for hiding this comment

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

devAddr is not a key.

}

type otaaKeys struct {
joinEUI, appKey, nwkKey *string
Copy link
Member

Choose a reason for hiding this comment

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

joinEUI is not a key.

return mode == "OTAA"
}

func (p Profile) SetFields(dev *ttnpb.EndDevice, fpStore *frequencyplans.Store, noSession bool) (err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add comments to exported functions.


type Profile struct{ *types.LoRaWANDeviceProfile }

func splitMacVersion(v string) (string, string) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: This is only used once. You can consider embedding it.


abp, otaa := d.sessionKeys()

if otaa.appKey != nil {
Copy link
Member

Choose a reason for hiding this comment

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

If the appKey is nil, we should error.

return nil
}

if dev.Session == nil {
Copy link
Member

Choose a reason for hiding this comment

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

idem

return errInvalidKey.WithAttributes("key", aws.ToString(abp.appSKey)).WithCause(err)
}
} else {
dev.Session.Keys.AppSKey.Key = random.Bytes(16)
Copy link
Member

@KrishnaIyer KrishnaIyer Feb 13, 2025

Choose a reason for hiding this comment

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

How is this going to work? We can't just make up the AppSKey for the device session and expect the device to communicate with TTS right?

I think if migration with session is required and there are no session keys in the AWS device, we should error or skip the device with a warning.

Comment on lines 62 to 65
Ids: &ttnpb.EndDeviceIdentifiers{
ApplicationIds: &ttnpb.ApplicationIdentifiers{ApplicationId: s.config.AppID},
DeviceId: aws.ToString(resp.Id),
},
Copy link
Member

Choose a reason for hiding this comment

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

The EUIs for an end device are mandatory primary identifiers. This is technically correct but I don't feel comfortable passing the IDs out of a function without setting the EUIs.

Comment on lines 66 to 69
// If we are not exporting session keys, we can return early.
if noSession {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

How about if it's an ABP device? I think it would be better if we refactor abp, otaa := d.sessionKeys() to a setKeys() function that checks if the device is OTAA or ABP and then checks if session is required and sets the appropriate keys and fails when a particular required key is not found.

Copy link

Choose a reason for hiding this comment

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

@KrishnaIyer I will refactor this and fix all the above mentioned things.

But I think it is not possible to export the session context from the AWS IoT. Sorry for realizing this so late but I was a little bit confused by the ABP session keys and the implementation that I took over.

I checked the LoRaWAN specifications and the AWS API doc again and I think what we need for session context is for OTAA devices is the NwkSKey, AppSKey, FCntUp, FCntDown and the DevAddr but AWS doesn't provide these values for OTAA devices. It only provides the root keys

// OTAA device object for v1.0.x
type OtaaV1_0_x struct {

	// The AppEUI value. You specify this value when using LoRaWAN versions v1.0.2 or
	// v1.0.3.
	AppEui *string

	// The AppKey value.
	AppKey *string

	// The GenAppKey value.
	GenAppKey *string

	// The JoinEUI value. You specify this value instead of the AppEUI when using
	// LoRaWAN version v1.0.4.
	JoinEui *string

	noSmithyDocumentSerde
}

For ABP devices we have the session keys (but because by default ABP using the session keys instead of the root keys)

// Session keys for ABP v1.1
type SessionKeysAbpV1_0_x struct {

	// The AppSKey value.
	AppSKey *string

	// The NwkSKey value.
	NwkSKey *string

	noSmithyDocumentSerde
}

But AWS doesn't provide any of the counters FCntUp, FCntDown and for OTAA devices doesn't provide the DevAddr.

So in that sense we can only export the devices without the session context.


AWS SDK doc

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 see. Unfortunately, these are not in the API as well.

But AWS doesn't provide any of the counters FCntUp, FCntDown

What about FCntStart? What is it used for?

Ok then let's document the fact that OTAA devices need to rejoin. If FCntSTart isn't something we can use, then let's also document that exporting ABP is not supported. In both cases, please add links to AWS IoT API docs.

@halimi halimi requested a review from KrishnaIyer February 13, 2025 22:00
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.

Support migration from AWS IoT
4 participants