-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Support AWS IoT #146
Conversation
628b361
to
7786d85
Compare
ba6e5ba
to
4ca8a42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
91f4279
to
c3b739e
Compare
c3b739e
to
ee4a965
Compare
@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 |
There was a problem hiding this comment.
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.
pkg/source/awsiot/device.go
Outdated
} | ||
|
||
type abpKeys struct { | ||
appSKey, fNwkSIntKey, nwkSKey, sNwkSIntKey, devAddr *string |
There was a problem hiding this comment.
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.
pkg/source/awsiot/device.go
Outdated
} | ||
|
||
type otaaKeys struct { | ||
joinEUI, appKey, nwkKey *string |
There was a problem hiding this comment.
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.
pkg/source/awsiot/profile.go
Outdated
return mode == "OTAA" | ||
} | ||
|
||
func (p Profile) SetFields(dev *ttnpb.EndDevice, fpStore *frequencyplans.Store, noSession bool) (err error) { |
There was a problem hiding this comment.
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.
pkg/source/awsiot/profile.go
Outdated
|
||
type Profile struct{ *types.LoRaWANDeviceProfile } | ||
|
||
func splitMacVersion(v string) (string, string) { |
There was a problem hiding this comment.
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.
pkg/source/awsiot/device.go
Outdated
|
||
abp, otaa := d.sessionKeys() | ||
|
||
if otaa.appKey != nil { |
There was a problem hiding this comment.
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.
pkg/source/awsiot/device.go
Outdated
return nil | ||
} | ||
|
||
if dev.Session == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
pkg/source/awsiot/device.go
Outdated
return errInvalidKey.WithAttributes("key", aws.ToString(abp.appSKey)).WithCause(err) | ||
} | ||
} else { | ||
dev.Session.Keys.AppSKey.Key = random.Bytes(16) |
There was a problem hiding this comment.
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.
pkg/source/awsiot/source.go
Outdated
Ids: &ttnpb.EndDeviceIdentifiers{ | ||
ApplicationIds: &ttnpb.ApplicationIdentifiers{ApplicationId: s.config.AppID}, | ||
DeviceId: aws.ToString(resp.Id), | ||
}, |
There was a problem hiding this comment.
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.
pkg/source/awsiot/device.go
Outdated
// If we are not exporting session keys, we can return early. | ||
if noSession { | ||
return nil | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Summary
Closes #143
Changes
Main:
awsiot
sourceOther:
Command
.awsiot.Command
instead ofawsiot.AWSIoTCmd
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
devices.txt
devices.json
Regressions
...
Notes for Reviewers
Checklist
CHANGELOG.md
.