Skip to content

Instantly share code, notes, and snippets.

@sepfy
Created May 3, 2019 07:38
Show Gist options
  • Save sepfy/2a177427458f250c6e4ca12391d0070b to your computer and use it in GitHub Desktop.
Save sepfy/2a177427458f250c6e4ca12391d0070b to your computer and use it in GitHub Desktop.
Study LoraWAN
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Ref:
// https://www.eebreakdown.com/2017/01/lora-ii.html
// https://lora-alliance.org/sites/default/files/2018-07/lorawan1.0.3.pdf
typedef struct _Personalized {
// DevEUI: 64 bit -> Static
unsigned char DevEUI[8];
// AppEUI: 64 bit -> Static
unsigned char AppEUI[8];
// AppKey: 128 bit -> Static
unsigned char AppKey[16];
} Personalized;
typedef struct _Activated {
// DevAddr: 32 bit -> Dynamic
struct {
unsigned int NwkID:7;
unsigned int NwkAddr:25;
} DevAddr;
// NwkSKey: 128 bit -> Dynamic
unsigned char NwkSKey[16];
// AppSKey: 128 bit -> Dynamic
unsigned char AppSKey[16];
} Activated;
int JoinRequest(Personalized pers) {
unsigned char buf[18] = {0};
memcpy(buf, pers.AppEUI, 8);
memcpy(buf+4, pers.DevEUI, 4);
}
int main(void) {
Personalized p;
Activated a;
p.AppEUI[0] = 0x12;
p.AppEUI[1] = 0x34;
p.AppEUI[2] = 0x56;
p.AppEUI[3] = 0x78;
p.AppEUI[4] = 0x11;
p.AppEUI[5] = 0x22;
p.AppEUI[6] = 0x33;
p.AppEUI[7] = 0x44;
p.DevEUI[0] = 0x77;
p.DevEUI[1] = 0x55;
p.DevEUI[2] = 0x33;
p.DevEUI[3] = 0x11;
p.DevEUI[4] = 0x78;
p.DevEUI[5] = 0x56;
p.DevEUI[6] = 0x34;
p.DevEUI[7] = 0x12;
JoinRequest(p);
printf("Hello world\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment