| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- /*!
- * \file LoRaMac.h
- *
- * \brief LoRa MAC layer implementation
- *
- * \copyright Revised BSD License, see section \ref LICENSE.
- *
- * \code
- * ______ _
- * / _____) _ | |
- * ( (____ _____ ____ _| |_ _____ ____| |__
- * \____ \| ___ | (_ _) ___ |/ ___) _ \
- * _____) ) ____| | | || |_| ____( (___| | | |
- * (______/|_____)_|_|_| \__)_____)\____)_| |_|
- * (C)2013 Semtech
- *
- * ___ _____ _ ___ _ _____ ___ ___ ___ ___
- * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
- * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
- * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
- * embedded.connectivity.solutions===============
- *
- * \endcode
- *
- * \author Miguel Luis ( Semtech )
- *
- * \author Gregory Cristian ( Semtech )
- *
- * \author Daniel Jäckle ( STACKFORCE )
- *
- * \defgroup LORAMAC LoRa MAC layer implementation
- * This module specifies the API implementation of the LoRaMAC layer.
- * This is a placeholder for a detailed description of the LoRaMac
- * layer and the supported features.
- * \{
- *
- * \example classA/LoRaMote/main.c
- * LoRaWAN class A application example for the LoRaMote.
- *
- * \example classB/LoRaMote/main.c
- * LoRaWAN class B application example for the LoRaMote.
- *
- * \example classC/LoRaMote/main.c
- * LoRaWAN class C application example for the LoRaMote.
- */
- #ifndef __LORAMAC_H__
- #define __LORAMAC_H__
- // Includes board dependent definitions such as channels frequencies
- //#include "LoRaMac-board.h"
- /********************************
- Lora物理层帧结构定义
- ********************************/
- #include <stdio.h>
- #include <stdlib.h>
- //#include <malloc.h>
- #include <stdint.h>
- #include <stdbool.h>
- /*!
- * LoRaMAC Status
- */
- typedef enum eLoRaMacStatus
- {
- /*!
- * Service started successfully
- */
- LORAMAC_STATUS_OK,
- /*!
- * Service not started - LoRaMAC is busy
- */
- LORAMAC_STATUS_BUSY,
- /*!
- * Service unknown
- */
- LORAMAC_STATUS_SERVICE_UNKNOWN,
- /*!
- * Service not started - invalid parameter
- */
- LORAMAC_STATUS_PARAMETER_INVALID,
- /*!
- * Service not started - invalid frequency
- */
- LORAMAC_STATUS_FREQUENCY_INVALID,
- /*!
- * Service not started - invalid datarate
- */
- LORAMAC_STATUS_DATARATE_INVALID,
- /*!
- * Service not started - invalid frequency and datarate
- */
- LORAMAC_STATUS_FREQ_AND_DR_INVALID,
- /*!
- * Service not started - the device is not in a LoRaWAN
- */
- LORAMAC_STATUS_NO_NETWORK_JOINED,
- /*!
- * Service not started - playload lenght error
- */
- LORAMAC_STATUS_LENGTH_ERROR,
- /*!
- * Service not started - playload lenght error
- */
- LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR,
- /*!
- * Service not started - the device is switched off
- */
- LORAMAC_STATUS_DEVICE_OFF,
- }LoRaMacStatus_t;
- /*!
- * LoRaMAC frame types
- *
- * LoRaWAN Specification V1.0, chapter 4.2.1, table 1
- */
- typedef enum eLoRaMacFrameType
- {
- /*!
- * LoRaMAC join request frame
- */
- FRAME_TYPE_JOIN_REQ = 0x00,
- /*!
- * LoRaMAC join accept frame
- */
- FRAME_TYPE_JOIN_ACCEPT = 0x01,
- /*!
- * LoRaMAC unconfirmed up-link frame
- */
- FRAME_TYPE_DATA_UNCONFIRMED_UP = 0x02,
- /*!
- * LoRaMAC unconfirmed down-link frame
- */
- FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
- /*!
- * LoRaMAC confirmed up-link frame
- */
- FRAME_TYPE_DATA_CONFIRMED_UP = 0x04,
- /*!
- * LoRaMAC confirmed down-link frame
- */
- FRAME_TYPE_DATA_CONFIRMED_DOWN = 0x05,
- /*!
- * LoRaMAC RFU frame
- */
- FRAME_TYPE_RFU = 0x06,
- /*!
- * LoRaMAC proprietary frame
- */
- FRAME_TYPE_PROPRIETARY = 0x07,
- }LoRaMacFrameType_t;
- #define UP_LINK 0
- /*!
- * Frame direction definition for down-link communications
- */
- #define DOWN_LINK 1
- /*!
- * Sets the length of the LoRaMAC footer field.
- * Mainly indicates the MIC field length
- */
- #define LORAMAC_MFR_LEN 4
- /*!
- * LoRaMAC header field definition (MHDR field)
- *
- * LoRaWAN Specification V1.0, chapter 4.2
- */
- typedef union uLoRaMacHeader
- {
- /*!
- * Byte-access to the bits
- */
- uint8_t Value;
- /*!
- * Structure containing single access to header bits
- */
- struct sHdrBits
- {
- /*!
- * Major version
- */
- uint8_t Major : 2;
- /*!
- * RFU
- */
- uint8_t RFU : 3;
- /*!
- * Message type
- */
- uint8_t MType : 3;
- }Bits;
- }LoRaMacHeader_t;
- /*!
- * LoRaMAC frame control field definition (FCtrl)
- *
- * LoRaWAN Specification V1.0, chapter 4.3.1
- */
- typedef union uLoRaMacFrameCtrl
- {
- /*!
- * Byte-access to the bits
- */
- uint8_t Value;
- struct sCtrlBits
- {
- /*!
- * Frame options length
- */
- uint8_t FOptsLen : 4;
- /*!
- * Frame pending bit
- */
- uint8_t FPending : 1;
- /*!
- * Message acknowledge bit
- */
- uint8_t Ack : 1;
- /*!
- * ADR acknowledgment request bit
- */
- uint8_t AdrAckReq : 1;
- /*!
- * ADR control in frame header
- */
- uint8_t Adr : 1;
- }Bits;
- }LoRaMacFrameCtrl_t;
- /*!
- * Device IEEE EUI
- */
- //static uint8_t *LoRaMacDevEui;
- typedef struct
- {
- uint8_t ADR; //实际只用1bit
- uint8_t ADRACKReq; //实际只用1bit
- uint8_t ACK; //实际只用1bit
- uint8_t FOptsLen; //实际只用4bit
- }FCtrl_t;
- typedef struct
- {
- uint32_t DevAddr;
- LoRaMacFrameCtrl_t FCtrl;
- uint16_t FCnt;
- uint8_t Fopts; //变长,约定1字节
- }FHDR_t;
- typedef struct
- {
-
- uint8_t AppEUI[8]; //uint64_t AppEUI;
- uint8_t DevEUI[8]; //uint64_t DevEUI;
- uint16_t DevNonce;
- uint32_t AppNonce; //实际只用3字节
- uint32_t NetID; //实际只用3字节
- uint32_t DevAddr;
- uint8_t DLSettings;
- uint8_t RxDelay;
- uint8_t CFList[16];
- FHDR_t FHDR;
- uint8_t Fport; //变长,约定1字节
- uint8_t FRMPayload[128];
- }MACPayload_t;
- typedef struct
- {
- LoRaMacHeader_t MHDR;
- MACPayload_t MACPayload;
- uint32_t MIC;
- }PHYPayload_t;
- typedef struct sPHYPayload
- {
- PHYPayload_t *PHYPayload;
- struct sPHYPayload *Next;
- }sPHYPayload_t;
- void sendJoinRequest(void);
- void sendUnconfirmUp(void);
- #endif // __LORAMAC_H__
|