/*
 ---------------------------------------------------------------------------
 Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.

 LICENSE TERMS

 The redistribution and use of this software (with or without changes)
 is allowed without the payment of fees or royalties provided that:

  1. source code distributions include the above copyright notice, this
     list of conditions and the following disclaimer;

  2. binary distributions include the above copyright notice, this list
     of conditions and the following disclaimer in their documentation;

  3. the name of the copyright holder is not used to endorse products
     built using this software without specific written permission.

 DISCLAIMER

 This software is provided 'as is' with no explicit or implied warranties
 in respect of its properties, including, but not limited to, correctness
 and/or fitness for purpose.
 ---------------------------------------------------------------------------
 Issue 09/09/2006

 This is an AES implementation that uses only 8-bit byte operations on the
 cipher state.
 */
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef __COMMON_H
#define __COMMON_H

#include <sys/epoll.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include "dy_utils/period_service.h"
#include "ipc_session.h"
#include "lnxall_list.h"
#include "dy_utils/dy_common.h"
#include "dy_utils/dy_ds.h"
#include "dy_utils/kv_array.h"
#include "dy_utils/dy_ipc.h"
#include "dy_utils/led.h"

#define LORAWAN_NODE_STATUS_BAK_FILE NODES_CFG"/lorawan-2ch_status.bak"


int loraWan_common_init();
int loraWan_devs_update(nodes_cfg_table_t *nodes_cfg_table);
int loraWan_mqtt_client_init(void);
void transmit_imme_msg_confirm(char *deveui_hex);
int loraWan_data_uplink(void* devdata, void* metadata, void* payload,int fsize);

node_cfg_t* loraWan_cfg_search_by_sn(char *sn);
node_cfg_t* loraWan_cfg_search_by_deveui(char *deveui);
bool fetch_class_A_down_msg(void *deveui_hex,void *paylaod,uint32_t *len,int maxsize);
bool fetch_class_C_down_msg_to_transmit(struct devinfo *devinfo,char *payload,int *len);
void period_service_poll(void);
void node_status_report();
int load_lorawan_config();
#endif  //__COMMON_H

