build: W600-SDK importiert, Firmware-Build und Hello am EVK
Docker-Build mit gcc-arm-none-eabi 4.9-2014q4 (statt Homebrew-Cask) verwendet, Dockerfile/tools/docker.sh dafür aus Task 13 vorgezogen. cmake/sdk.cmake schont gcc 4.9 (kennt -fcommon/-Wno-error=... nicht). Zwei zusätzliche SDK-Stubs (EarlyInit, pre_gpio_config) in src/sys/sdk_stubs.c ergänzt, siehe sdk/PATCHES.md.
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* @file aes.h
|
||||
* @brief AES functions
|
||||
* @copyright (c) 2003-2006, Jouni Malinen <jkmaline@cc.hut.fi>
|
||||
*
|
||||
* @note This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
//#include "crypto/cryptoApi.h"
|
||||
#include <stddef.h>
|
||||
#include "wm_type_def.h"
|
||||
#define USE_AES
|
||||
#define PSPUBLIC
|
||||
#ifndef CRYPT_INVALID_KEYSIZE
|
||||
#define CRYPT_INVALID_KEYSIZE -21
|
||||
#endif
|
||||
#ifndef MAXBLOCKSIZE
|
||||
#define MAXBLOCKSIZE 24
|
||||
#endif
|
||||
|
||||
#define STORE32H(x, y) { \
|
||||
(y)[0] = (unsigned char)(((x)>>24)&255); \
|
||||
(y)[1] = (unsigned char)(((x)>>16)&255); \
|
||||
(y)[2] = (unsigned char)(((x)>>8)&255); \
|
||||
(y)[3] = (unsigned char)((x)&255); \
|
||||
}
|
||||
|
||||
#define LOAD32H(x, y) { \
|
||||
x = ((unsigned long)((y)[0] & 255)<<24) | \
|
||||
((unsigned long)((y)[1] & 255)<<16) | \
|
||||
((unsigned long)((y)[2] & 255)<<8) | \
|
||||
((unsigned long)((y)[3] & 255)); \
|
||||
}
|
||||
|
||||
#define byte(x, n) (((x) >> (8 * (n))) & 255)
|
||||
|
||||
#define ROR(x, y) \
|
||||
( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | \
|
||||
((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
||||
|
||||
#define psTraceCrypto(x)
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
Universal return codes
|
||||
*/
|
||||
#define PS_SUCCESS 0
|
||||
#define PS_FAILURE -1
|
||||
|
||||
/* NOTE: Failure return codes MUST be < 0 */
|
||||
/* NOTE: The range for core error codes should be between -2 and -29 */
|
||||
#define PS_ARG_FAIL -6 /* Failure due to bad function param */
|
||||
#define PS_PLATFORM_FAIL -7 /* Failure as a result of system call error */
|
||||
#define PS_MEM_FAIL -8 /* Failure to allocate requested memory */
|
||||
#define PS_LIMIT_FAIL -9 /* Failure on sanity/limit tests */
|
||||
#define PS_UNSUPPORTED_FAIL -10 /* Unimplemented feature error */
|
||||
#define PS_DISABLED_FEATURE_FAIL -11 /* Incorrect #define toggle for feature */
|
||||
#define PS_PROTOCOL_FAIL -12 /* A protocol error occurred */
|
||||
#define PS_TIMEOUT_FAIL -13 /* A timeout occurred and MAY be an error */
|
||||
#define PS_INTERRUPT_FAIL -14 /* An interrupt occurred and MAY be an error */
|
||||
#define PS_PENDING -15 /* In process. Not necessarily an error */
|
||||
#define PS_EAGAIN -16 /* Try again later. Not necessarily an error */
|
||||
|
||||
#define PS_TRUE 1
|
||||
#define PS_FALSE 0
|
||||
|
||||
//typedef int int32; //µ÷ÓÃwm_type_def.h
|
||||
//typedef unsigned int uint32;
|
||||
//typedef short int16;
|
||||
//typedef unsigned short uint16;
|
||||
//typedef unsigned char uint8;
|
||||
|
||||
//typedef long long int64;
|
||||
//typedef unsigned long long uint64;
|
||||
//#if (GCC_COMPILE==0)
|
||||
//typedef unsigned int size_t;
|
||||
//#endif
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifdef USE_AES
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
#ifndef USE_AES_CBC_EXTERNAL
|
||||
typedef struct {
|
||||
unsigned int eK[64], dK[64];
|
||||
int Nr;
|
||||
} psAesKey_t;
|
||||
|
||||
typedef struct {
|
||||
int blocklen;
|
||||
unsigned char IV[16];
|
||||
psAesKey_t key;
|
||||
#if defined(USE_AES_GCM) || defined(USE_AES_CCM)
|
||||
unsigned char EncCtr[16];
|
||||
unsigned char CtrBlock[16];
|
||||
#endif
|
||||
#ifdef USE_AES_GCM
|
||||
unsigned char gInit[16];
|
||||
unsigned int TagTemp[4];
|
||||
unsigned char Hash_SubKey[16];
|
||||
unsigned int ProcessedBitCount[4];
|
||||
unsigned int InputBufferCount;
|
||||
unsigned int OutputBufferCount;
|
||||
union
|
||||
{
|
||||
unsigned char Buffer[128];
|
||||
unsigned int BufferAlignment;
|
||||
} Input;
|
||||
#endif /* USE_AES_GCM */
|
||||
#ifdef USE_AES_CCM
|
||||
unsigned int ccmTagTemp[16 / sizeof(unsigned int)]; /* 32 */
|
||||
union
|
||||
{
|
||||
/* Used for formatting IV. */
|
||||
unsigned char Temporary[16];
|
||||
/* Used for processing Mac. */
|
||||
unsigned char Y0[16];
|
||||
} u; /* 48 */
|
||||
#endif /* USE_AES_CCM */
|
||||
} psAesCipher_t;
|
||||
|
||||
typedef union {
|
||||
#ifdef USE_AES
|
||||
psAesCipher_t aes;
|
||||
#endif
|
||||
} psAesCipherContext_t;
|
||||
|
||||
#endif /* USE_AES_CBC_EXTERNAL */
|
||||
|
||||
#endif /* USE_AES */
|
||||
|
||||
#if 0
|
||||
void * aes_encrypt_init(const u8 *key, size_t len);
|
||||
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
|
||||
void aes_encrypt_deinit(void *ctx);
|
||||
void * aes_decrypt_init(const u8 *key, size_t len);
|
||||
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
|
||||
void aes_decrypt_deinit(void *ctx);
|
||||
#endif
|
||||
|
||||
#ifndef USE_AES
|
||||
#error "Must Enable USE_AES in cryptoConfig.h!"
|
||||
#endif
|
||||
|
||||
#ifdef USE_AES
|
||||
/******************************************************************************/
|
||||
/*
|
||||
CBC Mode AES
|
||||
*/
|
||||
PSPUBLIC int psAesInit(psAesCipherContext_t *ctx, unsigned char *IV,
|
||||
unsigned char *key, unsigned int keylen);
|
||||
PSPUBLIC int psAesDecrypt(psAesCipherContext_t *ctx, unsigned char *ct,
|
||||
unsigned char *pt, unsigned int len);
|
||||
PSPUBLIC int psAesEncrypt(psAesCipherContext_t *ctx, unsigned char *pt,
|
||||
unsigned char *ct, unsigned int len);
|
||||
/*
|
||||
Block Mode AES
|
||||
*/
|
||||
PSPUBLIC int psAesInitKey(const unsigned char *key, unsigned int keylen,
|
||||
psAesKey_t *skey);
|
||||
PSPUBLIC void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
|
||||
psAesKey_t *skey);
|
||||
PSPUBLIC void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt,
|
||||
psAesKey_t *skey);
|
||||
|
||||
|
||||
|
||||
int aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
#endif
|
||||
|
||||
#endif /* AES_H */
|
||||
|
||||
@@ -0,0 +1,563 @@
|
||||
/**
|
||||
* @file wm_crypto_hard.h
|
||||
*
|
||||
* @brief hard crypto module
|
||||
*
|
||||
* @author dave
|
||||
*
|
||||
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
|
||||
#ifndef WM_CRYPTO_HARD_H
|
||||
#define WM_CRYPTO_HARD_H
|
||||
|
||||
#include "wm_type_def.h"
|
||||
#include "aes.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif /* min */
|
||||
|
||||
/** The base address of the registers of encryption/decryption module. */
|
||||
#define HR_CRYPTO_BASE_ADDR 0x40003200
|
||||
/** The address of the source text address register. */
|
||||
#define HR_CRYPTO_SRC_ADDR (HR_CRYPTO_BASE_ADDR + 0x00)
|
||||
/** The address of the encrypted/decrypted text address register. */
|
||||
#define HR_CRYPTO_DEST_ADDR (HR_CRYPTO_BASE_ADDR + 0x04)
|
||||
/** The address of the configuration register. */
|
||||
#define HR_CRYPTO_SEC_CFG (HR_CRYPTO_BASE_ADDR + 0x08)
|
||||
/** The address of the control register. */
|
||||
#define HR_CRYPTO_SEC_CTRL (HR_CRYPTO_BASE_ADDR + 0x0C)
|
||||
/** The address of the key0 register. */
|
||||
#define HR_CRYPTO_KEY0 (HR_CRYPTO_BASE_ADDR + 0x10)
|
||||
/** The address of the key1 register. */
|
||||
#define HR_CRYPTO_KEY1 (HR_CRYPTO_BASE_ADDR + 0x14)
|
||||
/** The address of the key2 register. */
|
||||
#define HR_CRYPTO_KEY2 (HR_CRYPTO_BASE_ADDR + 0x18)
|
||||
/** The address of the key3 register. */
|
||||
#define HR_CRYPTO_KEY3 (HR_CRYPTO_BASE_ADDR + 0x1C)
|
||||
/** The address of the key4 register. */
|
||||
#define HR_CRYPTO_KEY4 (HR_CRYPTO_BASE_ADDR + 0x20)
|
||||
/** The address of the key5 register. */
|
||||
#define HR_CRYPTO_KEY5 (HR_CRYPTO_BASE_ADDR + 0x24)
|
||||
|
||||
/** The address of the IV0 register. */
|
||||
#define HR_CRYPTO_IV0 (HR_CRYPTO_BASE_ADDR + 0x28)
|
||||
/** The address of the IV1 register. */
|
||||
#define HR_CRYPTO_IV1 (HR_CRYPTO_BASE_ADDR + 0x20)
|
||||
|
||||
/** The address of the encrypted/decrypted status register. */
|
||||
#define HR_CRYPTO_SEC_STS (HR_CRYPTO_BASE_ADDR + 0x30)
|
||||
|
||||
/** The address of the SHA1/MD5 digest0 register. */
|
||||
#define HR_CRYPTO_SHA1_DIGEST0 (HR_CRYPTO_BASE_ADDR + 0x34)
|
||||
/** The address of the SHA1/MD5 digest1 register. */
|
||||
#define HR_CRYPTO_SHA1_DIGEST1 (HR_CRYPTO_BASE_ADDR + 0x38)
|
||||
/** The address of the SHA1/MD5 digest2 register. */
|
||||
#define HR_CRYPTO_SHA1_DIGEST2 (HR_CRYPTO_BASE_ADDR + 0x3C)
|
||||
/** The address of the SHA1/MD5 digest3 register. */
|
||||
#define HR_CRYPTO_SHA1_DIGEST3 (HR_CRYPTO_BASE_ADDR + 0x40)
|
||||
/** The address of the SHA1 digest4 and CRC in/output register. */
|
||||
#define HR_CRYPTO_SHA1_DIGEST4 (HR_CRYPTO_BASE_ADDR + 0x44)
|
||||
/** The address of the RNG RESULT register. */
|
||||
#define HR_CRYPTO_RNG_RESULT (HR_CRYPTO_BASE_ADDR + 0x48)
|
||||
|
||||
|
||||
/** The address of the CRC in register. */
|
||||
#define HR_CRYPTO_CRC_KEY HR_CRYPTO_SHA1_DIGEST4
|
||||
/** The address of the CRC output register. */
|
||||
#define HR_CRYPTO_CRC_RESULT HR_CRYPTO_SHA1_DIGEST4
|
||||
|
||||
#define ERR_CRY_OK 0 ///< No error, everything OK.
|
||||
#define ERR_FAILURE -1 /* failure */
|
||||
#define ERR_ARG_FAIL -6 /* Failure due to bad function param */
|
||||
|
||||
//CRC
|
||||
#define OUTPUT_REFLECT 1
|
||||
#define INPUT_REFLECT 2
|
||||
|
||||
typedef enum __CRYPTO_METHOD
|
||||
{
|
||||
CRYPTO_METHOD_RSV=0,
|
||||
CRYPTO_METHOD_RC4,
|
||||
CRYPTO_METHOD_SHA1,
|
||||
CRYPTO_METHOD_AES,
|
||||
CRYPTO_METHOD_DES,
|
||||
CRYPTO_METHOD_3DES,
|
||||
CRYPTO_METHOD_CRC, ///< CRC
|
||||
CRYPTO_METHOD_MD5 ///< MD5
|
||||
}CRYPTO_METHOD;
|
||||
|
||||
/**
|
||||
* The enum of the encryption/decryption way.
|
||||
*/
|
||||
typedef enum __CRYPTO_WAY
|
||||
{
|
||||
CRYPTO_WAY_ENCRYPT=0, ///< Encryption
|
||||
CRYPTO_WAY_DECRYPT ///< Decryption
|
||||
}CRYPTO_WAY;
|
||||
|
||||
typedef enum __CRYPTO_RNG_SWITCH
|
||||
{
|
||||
CRYPTO_RNG_SWITCH_16 = 0,
|
||||
CRYPTO_RNG_SWITCH_32
|
||||
}CRYPTO_RNG_SWITCH;
|
||||
|
||||
/**
|
||||
* The enum of the encryption/decryption mode, only for (aes des 3des).
|
||||
*/
|
||||
typedef enum __CRYPTO_MODE
|
||||
{
|
||||
CRYPTO_MODE_ECB=0, ///< ECB
|
||||
CRYPTO_MODE_CBC, ///< CBC
|
||||
CRYPTO_MODE_CTR ///< CTR, only for AES
|
||||
}CRYPTO_MODE;
|
||||
/**
|
||||
* The enum of the CRC type.
|
||||
*/
|
||||
typedef enum __CRYPTO_CRC_TYPE
|
||||
{
|
||||
CRYPTO_CRC_TYPE_8=0, ///< 8 bits CRC
|
||||
CRYPTO_CRC_TYPE_16_MODBUS, ///< 16 bits Modbus CRC
|
||||
CRYPTO_CRC_TYPE_16_CCITT, ///< 16 bits CCITT CRC
|
||||
CRYPTO_CRC_TYPE_32 ///< 32 bits CRC
|
||||
}CRYPTO_CRC_TYPE;
|
||||
|
||||
/**
|
||||
* The struct of the CRC context.
|
||||
*/
|
||||
typedef struct {
|
||||
u32 state; ///< The initial value input and result value output.
|
||||
u8 type; ///< The type of CRC, refernec the CRYPTO_CRC_TYPE enum.
|
||||
u8 mode; ///< The mode of CRC, bit0 means output reflection and bit1 means input reflection.
|
||||
}psCrcContext_t;
|
||||
|
||||
#if 1
|
||||
|
||||
struct hsha1_state {
|
||||
#ifdef HAVE_NATIVE_INT64
|
||||
uint64 length;
|
||||
#else
|
||||
u32 lengthHi;
|
||||
u32 lengthLo;
|
||||
#endif /* HAVE_NATIVE_INT64 */
|
||||
u32 state[5], curlen;
|
||||
unsigned char buf[64];
|
||||
};
|
||||
struct hmd5_state {
|
||||
#ifdef HAVE_NATIVE_INT64
|
||||
uint64 length;
|
||||
#else
|
||||
u32 lengthHi;
|
||||
u32 lengthLo;
|
||||
#endif /* HAVE_NATIVE_INT64 */
|
||||
u32 state[4], curlen;
|
||||
unsigned char buf[64];
|
||||
};
|
||||
|
||||
typedef union {
|
||||
struct hsha1_state sha1;
|
||||
struct hmd5_state md5;
|
||||
} hsDigestContext_t;
|
||||
|
||||
typedef u32 hstm_digit;
|
||||
typedef struct {
|
||||
s16 used, alloc, sign;
|
||||
hstm_digit *dp;
|
||||
} hstm_int;
|
||||
|
||||
struct sha1_state {
|
||||
#ifdef HAVE_NATIVE_INT64
|
||||
u64 length;
|
||||
#else
|
||||
u32 lengthHi;
|
||||
u32 lengthLo;
|
||||
#endif /* HAVE_NATIVE_INT64 */
|
||||
u32 state[5], curlen;
|
||||
unsigned char buf[64];
|
||||
};
|
||||
|
||||
struct md5_state {
|
||||
#ifdef HAVE_NATIVE_INT64
|
||||
u64 length;
|
||||
#else
|
||||
u32 lengthHi;
|
||||
u32 lengthLo;
|
||||
#endif /* HAVE_NATIVE_INT64 */
|
||||
u32 state[4], curlen;
|
||||
unsigned char buf[64];
|
||||
};
|
||||
|
||||
typedef union {
|
||||
struct sha1_state sha1;
|
||||
struct md5_state md5;
|
||||
} psDigestContext_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char state[256];
|
||||
u32 byteCount;
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
} psRc4Key_t;
|
||||
#define DES3_KEY_LEN 24
|
||||
#define DES3_IV_LEN 8
|
||||
#define DES_KEY_LEN 8
|
||||
|
||||
typedef struct {
|
||||
u32 ek[3][32], dk[3][32];
|
||||
} psDes3Key_t;
|
||||
|
||||
/*
|
||||
A block cipher CBC structure
|
||||
*/
|
||||
typedef struct {
|
||||
s32 blocklen;
|
||||
unsigned char IV[8];
|
||||
psDes3Key_t key;
|
||||
} des3_CBC;
|
||||
|
||||
typedef union {
|
||||
psRc4Key_t arc4;
|
||||
des3_CBC des3;
|
||||
psAesCipher_t aes;
|
||||
} psCipherContext_t;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief This function is used to stop random produce.
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_random_stop(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function initializes random digit seed and BIT number.
|
||||
*
|
||||
* @param[in] seed The random digit seed.
|
||||
* @param[in] rng_switch The random digit bit number. (0: 16bit 1:32bit)
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_random_init(u32 seed, CRYPTO_RNG_SWITCH rng_switch);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is used to get random digit content.
|
||||
*
|
||||
* @param[in] out Pointer to the output of random digit.
|
||||
* @param[in] len The random digit bit number will output.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_random_bytes(unsigned char *out, u32 len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function initializes a RC4 encryption algorithm,
|
||||
* i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] key Pointer to the key.
|
||||
* @param[in] keylen the length of key.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
|
||||
*
|
||||
* @note The first parameter ctx must be a structure which is allocated externally.
|
||||
* And all of Context parameters in the initializing methods should be allocated externally too.
|
||||
*/
|
||||
int tls_crypto_rc4_init(psCipherContext_t * ctx, const unsigned char *key, u32 keylen);
|
||||
|
||||
/**
|
||||
* @brief This function encrypts a variable length data stream according to RC4.
|
||||
* The RC4 algorithm it generates a "keystream" which is simply XORed with the plaintext to produce the ciphertext stream.
|
||||
* Decryption is exactly the same as encryption. This function also decrypts a variable length data stream according to RC4.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
|
||||
* @param[in] out Pointer to the resulting ciphertext data stream.
|
||||
* @param[in] len Length of the plaintext data stream in octets.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note The address needs to be four-byte aligned, and it needs to operate in words, not in bytes.
|
||||
*/
|
||||
int tls_crypto_rc4(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len);
|
||||
|
||||
/**
|
||||
* @brief This function initializes a AES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] IV Pointer to the Initialization Vector
|
||||
* @param[in] key Pointer to the key.
|
||||
* @param[in] keylen the length of key.
|
||||
* @param[in] cbc the encryption mode, AES supports ECB/CBC/CTR modes.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_aes_init(psCipherContext_t * ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc);
|
||||
|
||||
/**
|
||||
* @brief This function encrypts or decrypts a variable length data stream according to AES.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
|
||||
* @param[in] out Pointer to the resulting ciphertext data stream.
|
||||
* @param[in] len Length of the plaintext data stream in octets.
|
||||
* @param[in] dec The cryption way which indicates encryption or decryption.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note The address needs to be four-byte aligned, and it needs to operate in words, not in bytes.
|
||||
*/
|
||||
int tls_crypto_aes_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec);
|
||||
|
||||
/**
|
||||
* @brief This function initializes a 3DES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] IV Pointer to the Initialization Vector
|
||||
* @param[in] key Pointer to the key.
|
||||
* @param[in] keylen the length of key.
|
||||
* @param[in] cbc the encryption mode, 3DES supports ECB/CBC modes.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_3des_init(psCipherContext_t * ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc);
|
||||
|
||||
/**
|
||||
* @brief This function encrypts or decrypts a variable length data stream according to 3DES.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
|
||||
* @param[in] out Pointer to the resulting ciphertext data stream.
|
||||
* @param[in] len Length of the plaintext data stream in octets.
|
||||
* @param[in] dec The cryption way which indicates encryption or decryption.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note The address needs to be four-byte aligned, and it needs to operate in words, not in bytes.
|
||||
*/
|
||||
int tls_crypto_3des_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec);
|
||||
|
||||
/**
|
||||
* @brief This function initializes a DES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] IV Pointer to the Initialization Vector
|
||||
* @param[in] key Pointer to the key.
|
||||
* @param[in] keylen the length of key.
|
||||
* @param[in] cbc the encryption mode, DES supports ECB/CBC modes.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_des_init(psCipherContext_t * ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc);
|
||||
|
||||
/**
|
||||
* @brief This function encrypts or decrypts a variable length data stream according to DES.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Cipher Context.
|
||||
* @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
|
||||
* @param[in] out Pointer to the resulting ciphertext data stream.
|
||||
* @param[in] len Length of the plaintext data stream in octets.
|
||||
* @param[in] dec The cryption way which indicates encryption or decryption.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note The address needs to be four-byte aligned, and it needs to operate in words, not in bytes.
|
||||
*/
|
||||
int tls_crypto_des_encrypt_decrypt(psCipherContext_t * ctx, unsigned char *in, unsigned char *out, u32 len, CRYPTO_WAY dec);
|
||||
|
||||
/**
|
||||
* @brief This function initializes a CRC algorithm, i.e. fills the psCrcContext_t structure pointed to by ctx with necessary data.
|
||||
*
|
||||
* @param[in] ctx Pointer to the CRC Context.
|
||||
* @param[in] key The initialization key.
|
||||
* @param[in] crc_type The CRC type, supports CRC8/CRC16 MODBUS/CRC16 CCITT/CRC32
|
||||
* @param[in] mode Set input or outpu reflect.
|
||||
* @param[in] dec The cryption way which indicates encryption or decryption.
|
||||
* see OUTPUT_REFLECT
|
||||
* see INPUT_REFLECT
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_crc_init(psCrcContext_t * ctx, u32 key, CRYPTO_CRC_TYPE crc_type, u8 mode);
|
||||
|
||||
/**
|
||||
* @brief This function updates the CRC value with a variable length bytes.
|
||||
* This function may be called as many times as necessary, so the message may be processed in blocks.
|
||||
*
|
||||
* @param[in] ctx Pointer to the CRC Context.
|
||||
* @param[in] in Pointer to a variable length bytes
|
||||
* @param[in] len The bytes 's length
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note The address needs to be four-byte aligned.
|
||||
*/
|
||||
int tls_crypto_crc_update(psCrcContext_t * ctx, unsigned char *in, u32 len);
|
||||
|
||||
/**
|
||||
* @brief This function ends a CRC operation and produces a CRC value.
|
||||
*
|
||||
* @param[in] ctx Pointer to the CRC Context.
|
||||
* @param[in] crc_val Pointer to the CRC value.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_crc_final(psCrcContext_t * ctx, u32 *crc_val);
|
||||
|
||||
/**
|
||||
* @brief This function initializes Message-Diggest context for usage in SHA1 algorithm, starts a new SHA1 operation and writes a new Digest Context.
|
||||
*
|
||||
* @param[in] md Pointer to the SHA1 Digest Context.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_crypto_sha1_init(psDigestContext_t * md);
|
||||
|
||||
/**
|
||||
* @brief Process a message block using SHA1 algorithm.
|
||||
* This function performs a SHA1 block update operation. It continues an SHA1 message-digest operation,
|
||||
* by processing InputLen-byte length message block pointed to by buf, and by updating the SHA1 context pointed to by md.
|
||||
* This function may be called as many times as necessary, so the message may be processed in blocks.
|
||||
*
|
||||
* @param[in] md Pointer to the SHA1 Digest Context.
|
||||
* @param[in] buf InputLen-byte length message block
|
||||
* @param[in] len The buf 's length
|
||||
*
|
||||
* @returnl None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_crypto_sha1_update(psDigestContext_t * md, const unsigned char *buf, u32 len);
|
||||
|
||||
/**
|
||||
* @brief This function ends a SHA1 operation and produces a Message-Digest.
|
||||
* This function finalizes SHA1 algorithm, i.e. ends an SHA1 Message-Digest operation,
|
||||
* writing the Message-Digest in the 20-byte buffer pointed to by hash in according to the information stored in context.
|
||||
*
|
||||
* @param[in] md Pointer to the SHA1 Digest Context.
|
||||
* @param[in] hash Pointer to the Message-Digest
|
||||
*
|
||||
* @retval 20 success, return the hash size.
|
||||
* @retval <0 failed
|
||||
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_sha1_final(psDigestContext_t * md, unsigned char *hash);
|
||||
|
||||
/**
|
||||
* @brief This function initializes Message-Diggest context for usage in MD5 algorithm, starts a new MD5 operation and writes a new Digest Context.
|
||||
* This function begins a MD5 Message-Diggest Algorithm, i.e. fills the psDigestContext_t structure pointed to by md with necessary data.
|
||||
* MD5 is the algorithm which takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input.
|
||||
* It is conjectured that it is computationally infeasible to produce two messages having the same message digest,
|
||||
* or to produce any message having a given prespecified target message digest.
|
||||
*
|
||||
* @param[in] md MD5 Digest Context.
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_crypto_md5_init(psDigestContext_t * md);
|
||||
|
||||
/**
|
||||
* @brief Process a message block using MD5 algorithm.
|
||||
* This function performs a MD5 block update operation. It continues an MD5 message-digest operation,
|
||||
* by processing InputLen-byte length message block pointed to by buf, and by updating the MD5 context pointed to by md.
|
||||
* This function may be called as many times as necessary, so the message may be processed in blocks.
|
||||
*
|
||||
* @param[in] md MD5 Digest Context.
|
||||
* @param[in] buf InputLen-byte length message block
|
||||
* @param[in] len The buf 's length
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_crypto_md5_update(psDigestContext_t * md, const unsigned char *buf, u32 len);
|
||||
|
||||
/**
|
||||
* @brief This function ends a MD5 operation and produces a Message-Digest.
|
||||
* This function finalizes MD5 algorithm, i.e. ends an MD5 Message-Digest operation,
|
||||
* writing the Message-Digest in the 16-byte buffer pointed to by hash in according to the information stored in context.
|
||||
*
|
||||
* @param[in] md MD5 Digest Context.
|
||||
* @param[in] hash the Message-Digest
|
||||
*
|
||||
* @retval 16 success, return the hash size.
|
||||
* @retval <0 failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_md5_final(psDigestContext_t * md, unsigned char *hash);
|
||||
|
||||
/**
|
||||
* @brief This function implements the large module power multiplication algorithm.
|
||||
* res = a**e (mod n)
|
||||
*
|
||||
* @param[in] a Pointer to a bignumber.
|
||||
* @param[in] e Pointer to a bignumber.
|
||||
* @param[in] n Pointer to a bignumber.
|
||||
* @param[out] res Pointer to the result bignumber.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_crypto_exptmod(hstm_int *a, hstm_int *e, hstm_int *n, hstm_int *res);
|
||||
|
||||
/**
|
||||
* @brief This function initializes the encryption module.
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_crypto_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
/**
|
||||
* @file wm_fwup.h
|
||||
*
|
||||
* @brief Firmware upgrade
|
||||
*
|
||||
* @author winnermicro
|
||||
*
|
||||
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
|
||||
#ifndef WM_FWUP_H
|
||||
#define WM_FWUP_H
|
||||
#include "wm_osal.h"
|
||||
#include "list.h"
|
||||
|
||||
/** firmware update status */
|
||||
#define TLS_FWUP_STATUS_OK (0)
|
||||
#define TLS_FWUP_STATUS_EINVALID (1)
|
||||
#define TLS_FWUP_STATUS_EMEM (2)
|
||||
#define TLS_FWUP_STATUS_EPERM (3)
|
||||
#define TLS_FWUP_STATUS_EBUSY (4)
|
||||
#define TLS_FWUP_STATUS_ESESSIONID (5)
|
||||
#define TLS_FWUP_STATUS_EIO (6)
|
||||
#define TLS_FWUP_STATUS_ESIGNATURE (7)
|
||||
#define TLS_FWUP_STATUS_ECRC (8)
|
||||
#define TLS_FWUP_STATUS_EUNDEF (9)
|
||||
|
||||
/** firmware signature */
|
||||
#define TLS_FWUP_IMAGE_SIGNATURE_WORD 0x64365577
|
||||
#define TLS_FWUP_IMAGE_SIGNATURE_WORD_B 0x62161900
|
||||
|
||||
/** firmware block size for one time */
|
||||
#define TLS_FWUP_BLK_SIZE 512
|
||||
|
||||
/** firmware update request status */
|
||||
#define TLS_FWUP_REQ_STATUS_IDLE (0)
|
||||
#define TLS_FWUP_REQ_STATUS_BUSY (1)
|
||||
#define TLS_FWUP_REQ_STATUS_SUCCESS (2)
|
||||
#define TLS_FWUP_REQ_STATUS_FIO (3)
|
||||
#define TLS_FWUP_REQ_STATUS_FSIGNATURE (4)
|
||||
#define TLS_FWUP_REQ_STATUS_FMEM (5)
|
||||
#define TLS_FWUP_REQ_STATUS_FCRC (6)
|
||||
#define TLS_FWUP_REQ_STATUS_FCOMPLETE (7)
|
||||
|
||||
/** firmware update state */
|
||||
#define TLS_FWUP_STATE_UNDEF (0xffff)
|
||||
#define TLS_FWUP_STATE_BUSY (1 << 0)
|
||||
#define TLS_FWUP_STATE_COMPLETE (1 << 1)
|
||||
#define TLS_FWUP_STATE_ERROR_IO (1 << 2)
|
||||
#define TLS_FWUP_STATE_ERROR_SIGNATURE (1 << 3)
|
||||
#define TLS_FWUP_STATE_ERROR_MEM (1 << 4)
|
||||
#define TLS_FWUP_STATE_ERROR_CRC (1 << 5)
|
||||
|
||||
#define TLS_FWUP_STATE_ERROR (TLS_FWUP_STATE_ERROR_IO | TLS_FWUP_STATE_ERROR_SIGNATURE | TLS_FWUP_STATE_ERROR_MEM | TLS_FWUP_STATE_ERROR_CRC)
|
||||
|
||||
/** update type 0:firmware, 1: data */
|
||||
#define TLS_FWUP_DEST_SPECIFIC_FIRMWARE (0)
|
||||
#define TLS_FWUP_DEST_SPECIFIC_DATA (1)
|
||||
|
||||
enum IMAGE_TYPE_ENUM{
|
||||
IMG_TYPE_OLD_PLAIN = 0,
|
||||
IMG_TYPE_FLASHBIN = 1,
|
||||
IMG_TYPE_SECBOOT = 2,
|
||||
IMG_TYPE_NEW_PLAIN = 3
|
||||
};
|
||||
enum {
|
||||
NOT_ZIP_FILE = 0,
|
||||
ZIP_FILE = 1
|
||||
};
|
||||
typedef struct __T_BOOTER
|
||||
{
|
||||
unsigned int magic_no;
|
||||
unsigned short img_type;
|
||||
unsigned short zip_type; /** image type zip flag, 0: non-zip, 1:zip*/
|
||||
unsigned int run_img_addr; /** run area image start address */
|
||||
unsigned int run_img_len; /** run area image length */
|
||||
unsigned int run_org_checksum; /** run area image checksum */
|
||||
unsigned int upd_img_addr; /** upgrade area image start address*/
|
||||
unsigned int upd_img_len; /** upgrade area image length*/
|
||||
unsigned int upd_checksum; /** upgrade area image checksum */
|
||||
unsigned int upd_no;
|
||||
unsigned char ver[16];
|
||||
unsigned int hd_checksum;
|
||||
} T_BOOTER;
|
||||
|
||||
/** Structure for firmware image header */
|
||||
struct tls_fwup_image_hdr {
|
||||
u32 magic;
|
||||
u8 crc8;
|
||||
u8 dest_specific;
|
||||
u16 dest_offset; // unit: 4KB, valid when dest_specific is TRUE
|
||||
u32 file_len;
|
||||
char time[4];
|
||||
};
|
||||
|
||||
/** Structure for one packet data */
|
||||
struct tls_fwup_block {
|
||||
u16 number; //0~Sum-1
|
||||
u16 sum;
|
||||
u8 data[TLS_FWUP_BLK_SIZE];
|
||||
u32 crc32;
|
||||
u8 pad[8];
|
||||
};
|
||||
|
||||
/** Enumeration for image soure when firmware update */
|
||||
enum tls_fwup_image_src {
|
||||
TLS_FWUP_IMAGE_SRC_LUART = 0, /**< LOW SPEED UART */
|
||||
TLS_FWUP_IMAGE_SRC_HUART, /**< HIGH SPEED UART */
|
||||
TLS_FWUP_IMAGE_SRC_HSPI, /**< HIGH SPEED SPI */
|
||||
TLS_FWUP_IMAGE_SRC_WEB /**< WEB SERVER */
|
||||
};
|
||||
|
||||
/** Structure for firmware update request */
|
||||
struct tls_fwup_request {
|
||||
struct dl_list list;
|
||||
u8 *data;
|
||||
u32 data_len;
|
||||
int status;
|
||||
void (*complete)(struct tls_fwup_request *request, void *arg);
|
||||
void *arg;
|
||||
};
|
||||
|
||||
/** Structure for firmware update */
|
||||
struct tls_fwup {
|
||||
struct dl_list wait_list;
|
||||
tls_os_sem_t *list_lock;
|
||||
|
||||
bool busy;
|
||||
enum tls_fwup_image_src current_image_src;
|
||||
u16 current_state;
|
||||
u32 current_session_id;
|
||||
|
||||
u32 received_len;
|
||||
u32 total_len;
|
||||
u32 updated_len;
|
||||
u32 program_base;
|
||||
u32 program_offset;
|
||||
s32 received_number;
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup FWUP_APIs FWUP APIs
|
||||
* @brief firmware upgrade APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup FWUP_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function is used to initialize firmware update task
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK initial success
|
||||
* @retval TLS_FWUP_STATUS_EBUSY already initialed
|
||||
* @retval TLS_FWUP_STATUS_EMEM memory error
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_init(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to enter firmware update progress.
|
||||
*
|
||||
* @param[in] image_src image file's source,
|
||||
from TLS_FWUP_IMAGE_SRC_LUART,
|
||||
TLS_FWUP_IMAGE_SRC_WEB,TLS_FWUP_IMAGE_SRC_HUART,
|
||||
TLS_FWUP_IMAGE_SRC_HSPI
|
||||
*
|
||||
* @retval non-zero successfully, return session id
|
||||
* @retval 0 failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
u32 tls_fwup_enter(enum tls_fwup_image_src image_src);
|
||||
|
||||
/**
|
||||
* @brief This function is used to exit firmware update progress.
|
||||
*
|
||||
* @param[in] session_id session identity of firmware update progress
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK exit success
|
||||
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
|
||||
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
|
||||
* @retval TLS_FWUP_STATUS_EBUSY update state is busy
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_exit(u32 session_id);
|
||||
|
||||
/**
|
||||
* @brief This function is used to start update progress
|
||||
*
|
||||
* @param[in] session_id current sessin id
|
||||
* @param[in] *data the data want to update
|
||||
* @param[in] data_len data length
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK updade success
|
||||
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
|
||||
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
|
||||
* @retval TLS_FWUP_STATUS_EINVALID invalid param
|
||||
* @retval TLS_FWUP_STATUS_EMEM memory error
|
||||
* @retval TLS_FWUP_STATUS_EIO write flash error
|
||||
* @retval TLS_FWUP_STATUS_ECRC crc error
|
||||
* @retval TLS_FWUP_STATUS_ESIGNATURE signature error
|
||||
* @retval TLS_FWUP_STATUS_EUNDEF other error
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_request_sync(u32 session_id, u8 *data, u32 data_len);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get current update status
|
||||
*
|
||||
* @param[in] session_id current sessin id
|
||||
*
|
||||
* @retval current state TLS_FWUP_STATUS_OK to TLS_FWUP_STATUS_EUNDEF
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
u16 tls_fwup_current_state(u32 session_id);
|
||||
|
||||
/**
|
||||
* @brief This function is used to reset the update information
|
||||
*
|
||||
* @param[in] session_id current sessin id
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK reset success
|
||||
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
|
||||
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
|
||||
* @retval TLS_FWUP_STATUS_EBUSY update state is busy
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_reset(u32 session_id);
|
||||
|
||||
/**
|
||||
* @brief This function is used to clear error update state
|
||||
*
|
||||
* @param[in] session_id current sessin id
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK reset success
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_clear_error(u32 session_id);
|
||||
|
||||
/**
|
||||
* @brief This function is used to set update state to
|
||||
TLS_FWUP_STATE_ERROR_CRC
|
||||
*
|
||||
* @param[in] session_id current sessin id
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK set success
|
||||
* @retval TLS_FWUP_STATUS_EPERM globle param is not initialed
|
||||
* @retval TLS_FWUP_STATUS_ESESSIONID error session id
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_set_crc_error(u32 session_id);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get progress's status
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval TRUE busy
|
||||
* @retval FALSE idle
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_get_status(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to set update packet number
|
||||
*
|
||||
* @param[in] number
|
||||
*
|
||||
* @retval TLS_FWUP_STATUS_OK success
|
||||
* @retval TLS_FWUP_STATE_UNDEF failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_set_update_numer(int number);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get received update packet number
|
||||
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval return current packet number
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_get_current_update_numer(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is used to get current session id
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval non-zoro session id
|
||||
* @retval 0 error
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_get_current_session_id(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to check image header
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval TRUE: success
|
||||
* @retval FALSE: failure
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_fwup_img_header_check(T_BOOTER *img_param);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* WM_FWUP_H */
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* File Name : wm_mem.h
|
||||
*
|
||||
* Description: memory manager Module
|
||||
*
|
||||
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author : dave
|
||||
*
|
||||
* Date : 2014-6-12
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef WM_MEM_H
|
||||
#define WM_MEM_H
|
||||
|
||||
|
||||
#include "wm_type_def.h"
|
||||
//#define WM_MEM_DEBUG 1
|
||||
#if WM_MEM_DEBUG
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#define MEM_HEADER_PATTERN 0x76028412
|
||||
#define MEM_TAILER_PATTERN 0x83395627
|
||||
#define MEM_FREED_PATTERN 0x82962503
|
||||
|
||||
extern u32 alloc_heap_mem_bytes;
|
||||
extern u32 alloc_heap_mem_blk_cnt;
|
||||
extern u32 alloc_heap_mem_max_size;
|
||||
|
||||
//
|
||||
// Note: it's important that the size of MP_MEMORY_BLOCK structure
|
||||
// be multiple of 16 bytes.
|
||||
//
|
||||
typedef struct _MEMORY_BLOCK {
|
||||
|
||||
struct dl_list list; /**< Pointer to next and previous blocks */
|
||||
char *file; /**< name of the file which is doing the allocation */
|
||||
u32 pad; /**< pad to make the size of whole structure multiple of 16 bytes */
|
||||
u32 line; /**< line number where allocated */
|
||||
u32 length; /**< ulong index of trailer (=(length/4)-1 relative to data start */
|
||||
u32 header_pattern; /**< To help detect underflows. A trailer is also added to find overflows */
|
||||
} MEMORY_BLOCK, *PMEMORY_BLOCK;
|
||||
typedef struct _MEMORY_PATTERN{
|
||||
u32 pattern0;
|
||||
//u32 pattern1;
|
||||
//u32 pattern2;
|
||||
//u32 pattern3;
|
||||
}MEMORY_PATTERN, *PMEMORY_PATTERN;
|
||||
void mem_free_debug(void *p, char* file, int line);
|
||||
#define tls_mem_free(p) mem_free_debug( p, __FILE__, __LINE__)
|
||||
void *mem_alloc_debug(u32 size, char* file, int line);
|
||||
void mem_free_allocated_blocks(void);
|
||||
#define tls_mem_alloc(size) mem_alloc_debug(size, __FILE__, __LINE__)
|
||||
void * mem_realloc_debug(void *mem_address, u32 size, char* file, int line);
|
||||
#define tls_mem_realloc(mem_address, size) mem_realloc_debug(mem_address, size, __FILE__, __LINE__)
|
||||
|
||||
void *mem_calloc_debug(u32 n,u32 size,char * file,int line);
|
||||
#define tls_mem_calloc(n, size) mem_calloc_debug(n, size, __FILE__, __LINE__)
|
||||
void tls_mem_alloc_info(void);
|
||||
int is_safe_addr_debug(void* p, u32 len, char* file, int line);
|
||||
#define tls_is_safe_addr(p, len) is_safe_addr_debug(p, len, __FILE__, __LINE__)
|
||||
#if 1
|
||||
#define MEMCPY memcpy
|
||||
#define SMEMCPY MEMCPY
|
||||
#else
|
||||
#define MEMCPY(dst,src,len) do { \
|
||||
if(tls_is_safe_addr(dst, len)){ \
|
||||
memcpy(dst,src,len);}}while(0)
|
||||
|
||||
#define SMEMCPY(dst,src,len) do { \
|
||||
if(tls_is_safe_addr(dst, len)){ \
|
||||
memcpy(dst,src,len);}}while(0)
|
||||
#endif
|
||||
#else /* WM_MEM_DEBUG */
|
||||
|
||||
void * mem_alloc_debug(u32 size);
|
||||
void mem_free_debug(void *p);
|
||||
void * mem_realloc_debug(void *mem_address, u32 size);
|
||||
void *mem_calloc_debug(u32 length, u32 size);
|
||||
|
||||
/**
|
||||
* @defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup MEM_APIs MEM APIs
|
||||
* @brief memory manager APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup MEM_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function is called by memory allocation
|
||||
*
|
||||
* @param[in] size
|
||||
*
|
||||
* @retval NULL malloc failed
|
||||
* @retval pointer pointer to the address of the allocated memory
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
#define tls_mem_alloc(size) mem_alloc_debug(size)
|
||||
|
||||
/**
|
||||
* @brief This function is used to free memory
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
#define tls_mem_free mem_free_debug
|
||||
|
||||
/**
|
||||
* @brief This function is used to realloc memory
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval NULL realloc failed
|
||||
* @retval Pointer pointer to the address of the allocated memory
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
#define tls_mem_realloc mem_realloc_debug
|
||||
|
||||
/**
|
||||
* @brief This function is used to calloc memory
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval NULL realloc failed
|
||||
* @retval Pointer pointer to the address of the allocated memory
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
#define tls_mem_calloc mem_calloc_debug
|
||||
|
||||
/**
|
||||
* @brief This function is used to copy memory content from one address to another address
|
||||
*
|
||||
* @param[in] dst pointer to destination address
|
||||
* @param[in] src pointer to source address
|
||||
* @param[in] len length to copy
|
||||
*
|
||||
* @retval dst
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
#define MEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
|
||||
/**
|
||||
* @brief This function is used to copy memory content from one address to another address
|
||||
*
|
||||
* @param[in] dst pointer to destination address
|
||||
* @param[in] src pointer to source address
|
||||
* @param[in] len length to copy
|
||||
*
|
||||
* @retval dst
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
|
||||
/**
|
||||
* @brief This function is used to get available memory
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note This api just can get coarse memory that is remained
|
||||
*/
|
||||
unsigned int tls_mem_get_avail_heapsize(void);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* WM_MEM_DEBUG */
|
||||
|
||||
#endif /* TLS_MEM_H */
|
||||
|
||||
@@ -0,0 +1,615 @@
|
||||
/**
|
||||
* @file wm_params.h
|
||||
*
|
||||
* @brief param manager Module
|
||||
*
|
||||
* @author winnermicro
|
||||
*
|
||||
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
#ifndef TLS_PARAMS_H
|
||||
#define TLS_PARAMS_H
|
||||
|
||||
#include "wm_type_def.h"
|
||||
|
||||
/***************************************************************************************
|
||||
ID | Data Type
|
||||
***************************************************************************************
|
||||
TLS_PARAM_ID_SSID | struct tls_param_ssid ssid
|
||||
TLS_PARAM_ID_ENCRY | u8 encry
|
||||
TLS_PARAM_ID_KEY | struct tls_param_key key
|
||||
TLS_PARAM_ID_IP | struct tls_param_ip ipcfg
|
||||
TLS_PARAM_ID_AUTOMODE | u8 auto_mode
|
||||
TLS_PARAM_ID_DEFSOCKET | N/A
|
||||
TLS_PARAM_ID_BSSID | struct tls_param_bssid bssid
|
||||
TLS_PARAM_ID_CHANNEL | u8 channel
|
||||
TLS_PARAM_ID_CHANNEL_EN | u8 channel_enable
|
||||
TLS_PARAM_ID_COUNTRY_REGION | u8 wireless_region
|
||||
TLS_PARAM_ID_WPROTOCOL | u8 wireless_protocol
|
||||
TLS_PARAM_ID_ADHOC_AUTOCREATE | N/A
|
||||
TLS_PARAM_ID_ROAMING | u8 auto_roam
|
||||
TLS_PARAM_ID_AUTO_RETRY_CNT | N/A
|
||||
TLS_PARAM_ID_WBGR | struct tls_param_bgr wbgr
|
||||
TLS_PARAM_ID_USRINTF | N/A
|
||||
TLS_PARAM_ID_AUTO_TRIGGER_LENGTH | N/A
|
||||
TLS_PARAM_ID_DEBUG_MODE | N/A
|
||||
TLS_PARAM_ID_HARDVERSION | struct tls_param_hardware_version hardware_v
|
||||
TLS_PARAM_ID_BRDSSID | u8 ssid_broadcast_enable
|
||||
TLS_PARAM_ID_DNSNAME | u8 local_dnsname[32]
|
||||
TLS_PARAM_ID_DEVNAME | u8 local_device_name[32]
|
||||
TLS_PARAM_ID_PSM | u8 auto_powersave
|
||||
TLS_PARAM_ID_ORAY_CLIENT | N/A
|
||||
TLS_PARAM_ID_UPNP | N/A
|
||||
TLS_PARAM_ID_UART | struct tls_param_uart uart_cfg
|
||||
TLS_PARAM_ID_WPS | struct tls_param_wps wps
|
||||
TLS_PARAM_ID_AUTO_TRIGGER_PERIOD | N/A
|
||||
TLS_PARAM_ID_ESCAPE_CHAR | N/A
|
||||
TLS_PARAM_ID_ESCAPE_PERIOD | N/A
|
||||
TLS_PARAM_ID_IO_MODE | N/A
|
||||
TLS_PARAM_ID_CMD_MODE | N/A
|
||||
TLS_PARAM_ID_PASSWORD | u8 PassWord[6]
|
||||
TLS_PARAM_ID_CHANNEL_LIST | u16 channellist
|
||||
TLS_PARAM_ID_WEBS_CONFIG | struct tls_webs_cfg WebsCfg
|
||||
TLS_PARAM_ID_ONESHOT_CFG | u8 oneshotflag
|
||||
TLS_PARAM_ID_SHA1 | N/A
|
||||
TLS_PARAM_ID_ORIGIN_KEY | N/A
|
||||
TLS_PARAM_ID_ORIGIN_SSID | N/A
|
||||
TLS_PARAM_ID_AUTO_RECONNECT | u8 auto_reconnect
|
||||
***************************************************************************************/
|
||||
|
||||
#define TLS_PARAM_STATUS_OK (0)
|
||||
#define TLS_PARAM_STATUS_EINVALID (1)
|
||||
#define TLS_PARAM_STATUS_EMEM (2)
|
||||
#define TLS_PARAM_STATUS_EIO (3)
|
||||
#define TLS_PARAM_STATUS_EPERM (4)
|
||||
#define TLS_PARAM_STATUS_EINVALIDID (5)
|
||||
|
||||
/** MACRO of Magic number initial value */
|
||||
#define TLS_PARAM_INIT_MAGIC (0xffffffff)
|
||||
/** MACRO of Magic number valid value */
|
||||
#define TLS_PARAM_MAGIC (0x4947414d)
|
||||
|
||||
/** MACRO of parameter partition number */
|
||||
#define TLS_PARAM_PARTITION_NUM (2)
|
||||
|
||||
/** MACRO of parameter identity */
|
||||
#define TLS_PARAM_ID_ALL (-1)
|
||||
#define TLS_PARAM_ID_SSID (0)
|
||||
#define TLS_PARAM_ID_ENCRY (1)
|
||||
#define TLS_PARAM_ID_KEY (2)
|
||||
#define TLS_PARAM_ID_IP (3)
|
||||
#define TLS_PARAM_ID_AUTOMODE (4)
|
||||
#define TLS_PARAM_ID_DEFSOCKET (5)
|
||||
#define TLS_PARAM_ID_BSSID (6)
|
||||
#define TLS_PARAM_ID_CHANNEL (7)
|
||||
#define TLS_PARAM_ID_CHANNEL_EN (8)
|
||||
#define TLS_PARAM_ID_COUNTRY_REGION (9)
|
||||
#define TLS_PARAM_ID_WPROTOCOL (10)
|
||||
#define TLS_PARAM_ID_ADHOC_AUTOCREATE (11)
|
||||
#define TLS_PARAM_ID_ROAMING (12)
|
||||
#define TLS_PARAM_ID_AUTO_RETRY_CNT (13)
|
||||
#define TLS_PARAM_ID_WBGR (14)
|
||||
#define TLS_PARAM_ID_USRINTF (15)
|
||||
#define TLS_PARAM_ID_AUTO_TRIGGER_LENGTH (16)
|
||||
#define TLS_PARAM_ID_DEBUG_MODE (17)
|
||||
#define TLS_PARAM_ID_HARDVERSION (18)
|
||||
#define TLS_PARAM_ID_BRDSSID (19)
|
||||
#define TLS_PARAM_ID_DNSNAME (20)
|
||||
#define TLS_PARAM_ID_DEVNAME (21)
|
||||
#define TLS_PARAM_ID_PSM (22)
|
||||
#define TLS_PARAM_ID_ORAY_CLIENT (23)
|
||||
#define TLS_PARAM_ID_UPNP (24)
|
||||
#define TLS_PARAM_ID_UART (26)
|
||||
#define TLS_PARAM_ID_WPS (27)
|
||||
#define TLS_PARAM_ID_AUTO_TRIGGER_PERIOD (28)
|
||||
#define TLS_PARAM_ID_ESCAPE_CHAR (29)
|
||||
#define TLS_PARAM_ID_ESCAPE_PERIOD (30)
|
||||
#define TLS_PARAM_ID_IO_MODE (31)
|
||||
#define TLS_PARAM_ID_CMD_MODE (32)
|
||||
#define TLS_PARAM_ID_PASSWORD (33)
|
||||
#define TLS_PARAM_ID_CHANNEL_LIST (34)
|
||||
#define TLS_PARAM_ID_WEBS_CONFIG (35)
|
||||
#define TLS_PARAM_ID_ONESHOT_CFG (36)
|
||||
#define TLS_PARAM_ID_SHA1 (37)
|
||||
#define TLS_PARAM_ID_ORIGIN_KEY (38)
|
||||
#define TLS_PARAM_ID_ORIGIN_SSID (39)
|
||||
#define TLS_PARAM_ID_AUTO_RECONNECT (40)
|
||||
#define TLS_PARAM_ID_QUICK_CONNECT (41)
|
||||
#define TLS_PARAM_ID_KEY_CHANGE (42)
|
||||
#define TLS_PARAM_ID_SSID_CHANGE (43)
|
||||
#define TLS_PARAM_ID_SOFTAP_SSID (44)
|
||||
#define TLS_PARAM_ID_SOFTAP_PSK (45)
|
||||
#define TLS_PARAM_ID_SOFTAP_ENCRY (46)
|
||||
#define TLS_PARAM_ID_SOFTAP_KEY (47)
|
||||
#define TLS_PARAM_ID_SOFTAP_IP (48)
|
||||
#define TLS_PARAM_ID_SOFTAP_CHANNEL (49)
|
||||
#define TLS_PARAM_ID_SOFTAP_WBGR (50)
|
||||
|
||||
#define TLS_PARAM_ID_SNTP_SERVER1 (51)
|
||||
#define TLS_PARAM_ID_SNTP_SERVER2 (52)
|
||||
#define TLS_PARAM_ID_SNTP_SERVER3 (53)
|
||||
#define TLS_PARAM_ID_TEM_OFFSET (54)
|
||||
|
||||
#define TLS_PARAM_ID_MAX (55)
|
||||
/** MACRO of Physical moe of Ieee802.11 */
|
||||
#define TLS_PARAM_PHY_11BG_MIXED (0)
|
||||
#define TLS_PARAM_PHY_11B (1)
|
||||
#define TLS_PARAM_PHY_11BGN_MIXED (2)
|
||||
/** MACRO of Ieee802.11 Tx Rate for parameter set */
|
||||
#define TLS_PARAM_TX_RATEIDX_1M (0)
|
||||
#define TLS_PARAM_TX_RATEIDX_2M (1)
|
||||
#define TLS_PARAM_TX_RATEIDX_5_5M (2)
|
||||
#define TLS_PARAM_TX_RATEIDX_11M (3)
|
||||
#define TLS_PARAM_TX_RATEIDX_6M (4)
|
||||
#define TLS_PARAM_TX_RATEIDX_9M (5)
|
||||
#define TLS_PARAM_TX_RATEIDX_12M (6)
|
||||
#define TLS_PARAM_TX_RATEIDX_18M (7)
|
||||
#define TLS_PARAM_TX_RATEIDX_24M (8)
|
||||
#define TLS_PARAM_TX_RATEIDX_36M (9)
|
||||
#define TLS_PARAM_TX_RATEIDX_48M (10)
|
||||
#define TLS_PARAM_TX_RATEIDX_54M (11)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS0 (12)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS1 (13)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS2 (14)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS3 (15)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS4 (16)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS5 (17)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS6 (18)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS7 (19)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS8 (20)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS9 (21)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS10 (22)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS11 (23)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS12 (24)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS13 (25)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS14 (26)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS15 (27)
|
||||
#define TLS_PARAM_TX_RATEIDX_MCS32 (28)
|
||||
|
||||
|
||||
/** MACRO of SSID Broadcast */
|
||||
#define TLS_PARAM_SSIDBRD_DISABLE (0)
|
||||
#define TLS_PARAM_SSIDBRD_ENABLE (1)
|
||||
|
||||
#define TLS_PARAM_ROAM_DISABLE (0)
|
||||
#define TLS_PARAM_ROAM_ENABLE (1)
|
||||
|
||||
/** MACRO of Power Saving Mode */
|
||||
#define TLS_PARAM_PSM_DISABLE (0)
|
||||
#define TLS_PARAM_PSM_ENABLE (1)
|
||||
|
||||
#define TLS_PARAM_DDNS_DISABLE (0)
|
||||
#define TLS_PARAM_DDNS_ENABLE (1)
|
||||
|
||||
#define TLS_PARAM_AUTO_CREATE_ADHOC_DISABLE (0)
|
||||
#define TLS_PARAM_AUTO_CREATE_ADHOC_ENABLE (1)
|
||||
|
||||
#define TLS_PARAM_WPS_DISABLE (0)
|
||||
#define TLS_PARAM_WPS_ENABLE (1)
|
||||
#define TLS_PARAM_WPS_MODE_PIN (0)
|
||||
#define TLS_PARAM_WPS_MODE_PBC (1)
|
||||
#define TLS_PARAM_WPS_FLAG_NEGOTIATED (1 << 0)
|
||||
|
||||
#define TLS_PARAM_UPNP_DISABLE (0)
|
||||
#define TLS_PARAM_UPNP_ENABLE (1)
|
||||
|
||||
/** MACRO of IEEE802.11 Work MODE */
|
||||
#define TLS_PARAM_IEEE80211_INFRA (1)
|
||||
#define TLS_PARAM_IEEE80211_ADHOC (2)
|
||||
#define TLS_PARAM_IEEE80211_SOFTAP (4)
|
||||
|
||||
/** MACRO of Command or Transparent Mode */
|
||||
#define TLS_PARAM_MANUAL_MODE (0)
|
||||
#define TLS_PARAM_AUTO_MODE (1)
|
||||
|
||||
#define TLS_PARAM_ALWAYS_ONLINE_ENABLE (1)
|
||||
#define TLS_PARAM_ALWAYS_ONLINE_DISABLE (0)
|
||||
|
||||
/** MACRO of DHCP ENABLE or DISABLE */
|
||||
#define TLS_PARAM_DHCP_ENABLE (1)
|
||||
#define TLS_PARAM_DHCP_DISABLE (0)
|
||||
|
||||
/** MACRO of COUNTRY CODE for channel number */
|
||||
#define TLS_PARAM_REGION_0_BG_BAND (0) /* 1-11 */
|
||||
#define TLS_PARAM_REGION_1_BG_BAND (1) /* 1-13 */
|
||||
#define TLS_PARAM_REGION_2_BG_BAND (2) /* 10-11 */
|
||||
#define TLS_PARAM_REGION_3_BG_BAND (3) /* 10-13 */
|
||||
#define TLS_PARAM_REGION_4_BG_BAND (4) /* 14 */
|
||||
#define TLS_PARAM_REGION_5_BG_BAND (5) /* 1-14 */
|
||||
#define TLS_PARAM_REGION_6_BG_BAND (6) /* 3-9 */
|
||||
#define TLS_PARAM_REGION_7_BG_BAND (7) /* 5-13 */
|
||||
#define TLS_PARAM_REGION_MAXIMUM_BG_BAND TLS_PARAM_REGION_7_BG_BAND
|
||||
|
||||
/** MACRO of ENCRYPT TYPE */
|
||||
#define TLS_PARAM_ENCRY_OPEN (0)
|
||||
#define TLS_PARAM_ENCRY_WEP64 (1)
|
||||
#define TLS_PARAM_ENCRY_WEP128 (2)
|
||||
#define TLS_PARAM_ENCRY_WPA_PSK_TKIP (3)
|
||||
#define TLS_PARAM_ENCRY_WPA_PSK_AES (4)
|
||||
#define TLS_PARAM_ENCRY_WPA2_PSK_TKIP (5)
|
||||
#define TLS_PARAM_ENCRY_WPA2_PSK_AES (6)
|
||||
|
||||
/** MACRO of USER INTERFACE TYPE */
|
||||
#define TLS_PARAM_USR_INTF_LUART (0)
|
||||
#define TLS_PARAM_USR_INTF_HUART (1)
|
||||
#define TLS_PARAM_USR_INTF_HSPI (2)
|
||||
#define TLS_PARAM_USR_INTF_HSDIO (3)
|
||||
|
||||
/** MACRO of UART BAUDRATE */
|
||||
#define TLS_PARAM_UART_BAUDRATE_B600 (600)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B1200 (1200)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B1800 (1800)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B2400 (2400)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B4800 (4800)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B9600 (9600)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B19200 (19200)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B38400 (38400)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B57600 (57600)
|
||||
#define TLS_PARAM_UART_BAUDRATE_B115200 (115200)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B230400 (230400)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B460800 (460800)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B921600 (921600)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B1000000 (1000000)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B1250000 (1250000)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B1500000 (1500000)
|
||||
#define TLS_PARAM_HUART_BAUDRATE_B2000000 (2000000)
|
||||
|
||||
/** MACRO of UART PARITY */
|
||||
#define TLS_PARAM_UART_PARITY_NONE (0)
|
||||
#define TLS_PARAM_UART_PARITY_EVEN (1)
|
||||
#define TLS_PARAM_UART_PARITY_ODD (2)
|
||||
#define TLS_PARAM_UART_PARITY_MARK (3)
|
||||
#define TLS_PARAM_UART_PARITY_SPACE (4)
|
||||
|
||||
/** MACRO of UART STOP BITS */
|
||||
#define TLS_PARAM_UART_STOPBITS_1BITS (0)
|
||||
#define TLS_PARAM_UART_STOPBITS_2BITS (1)
|
||||
|
||||
/** MACRO of UART FLOW CONTROL */
|
||||
#define TLS_PARAM_UART_FLOW_DISABLE (0)
|
||||
#define TLS_PARAM_UART_FLOW_ENABLE (1)
|
||||
#define TLS_PARAM_HSPI_MAX_SCLK (33000000)
|
||||
/** MACRO of SOCKET PARAMETER */
|
||||
#define TLS_PARAM_SOCKET_TCP (0)
|
||||
#define TLS_PARAM_SOCKET_UDP (1)
|
||||
#define TLS_PARAM_SOCKET_CLIENT (0)
|
||||
#define TLS_PARAM_SOCKET_SERVER (1)
|
||||
#define TLS_PARAM_SOCKET_DEFAULT_PORT (60000)
|
||||
|
||||
/** Structure of hardware parameter */
|
||||
struct tls_param_hardware_version {
|
||||
u8 mark;
|
||||
u8 main;
|
||||
u8 sub;
|
||||
u8 material;
|
||||
u8 year;
|
||||
u8 week;
|
||||
u8 res[2];
|
||||
};
|
||||
|
||||
/** Structure of specified BSSID parameter */
|
||||
struct tls_param_bssid {
|
||||
u8 bssid_enable;
|
||||
u8 res;
|
||||
u8 bssid[6];
|
||||
};
|
||||
|
||||
/** Structure of SSID parameter */
|
||||
struct tls_param_ssid {
|
||||
u8 ssid[32];
|
||||
u32 ssid_len;
|
||||
};
|
||||
|
||||
/** Structure of TEM parameter */
|
||||
struct tls_param_tem_offset {
|
||||
u8 offset_len;
|
||||
s32 offset;
|
||||
};
|
||||
|
||||
/** Structure of KEY parameter */
|
||||
struct tls_param_key {
|
||||
u8 psk[64];
|
||||
u8 key_length;
|
||||
u8 key_index;
|
||||
u8 key_format;
|
||||
u8 res;
|
||||
};
|
||||
|
||||
/** Structure of original KEY parameter */
|
||||
struct tls_param_original_key {
|
||||
u8 psk[64];
|
||||
u32 key_length;
|
||||
};
|
||||
|
||||
/** Structure of SHA1 KEY parameter */
|
||||
struct tls_param_sha1{
|
||||
u8 psk_set;
|
||||
u8 psk[32];
|
||||
};
|
||||
|
||||
/** Structure of 802.11 bgn rate parameter */
|
||||
struct tls_param_bgr {
|
||||
u8 bg;
|
||||
u8 max_rate;
|
||||
u8 res[2];
|
||||
};
|
||||
|
||||
/** Structure of IP parameter */
|
||||
struct tls_param_ip {
|
||||
u8 dhcp_enable;
|
||||
u8 res[3];
|
||||
u8 ip[4];
|
||||
u8 netmask[4];
|
||||
u8 gateway[4];
|
||||
u8 dns1[4];
|
||||
u8 dns2[4];
|
||||
};
|
||||
|
||||
/** Structure of uart parameter */
|
||||
struct tls_param_uart {
|
||||
u32 baudrate;
|
||||
u8 stop_bits;
|
||||
u8 parity;
|
||||
u8 flow;
|
||||
u8 charsize;
|
||||
};
|
||||
|
||||
/** Structure of socket parameter */
|
||||
struct tls_param_socket {
|
||||
u8 protocol;
|
||||
u8 client_or_server;
|
||||
u16 port_num;
|
||||
u8 host[32];
|
||||
};
|
||||
|
||||
struct tls_param_wps {
|
||||
u8 wps_enable;
|
||||
u8 mode;
|
||||
u8 flag;
|
||||
u8 res;
|
||||
u8 pin[8];
|
||||
};
|
||||
|
||||
/** Structure of oray client */
|
||||
struct tls_param_oray_client {
|
||||
u32 oray_client_enable;
|
||||
u8 oray_client_user[32];
|
||||
u8 oray_client_pass[32];
|
||||
};
|
||||
|
||||
/** Structure of web server parameter */
|
||||
struct tls_webs_cfg {
|
||||
u8 AutoRun;
|
||||
u8 Reserved;
|
||||
u16 PortNum;
|
||||
};
|
||||
|
||||
/** Structure of user default parameter */
|
||||
typedef struct tls_user_param{
|
||||
|
||||
u8 wireless_protocol;
|
||||
u8 auto_mode;
|
||||
u8 dhcp_enable;
|
||||
u8 user_port_mode;
|
||||
|
||||
u8 ip[4];
|
||||
u8 netmask[4];
|
||||
u8 gateway[4];
|
||||
u8 dns[4];
|
||||
|
||||
u32 baudrate;
|
||||
|
||||
u8 socket_protocol;
|
||||
u8 socket_client_or_server;
|
||||
u16 socket_port_num;
|
||||
u8 socket_host[32];
|
||||
u8 auto_powersave;
|
||||
u8 PassWord[6];
|
||||
}ST_Wm_User_Param;
|
||||
|
||||
/**
|
||||
* @defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Param_APIs Param APIs
|
||||
* @brief Param manager APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Param_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function is used to initialize parameter's manage module
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK init success
|
||||
* @retval TLS_PARAM_STATUS_EMEM memory error
|
||||
* @retval TLS_PARAM_STATUS_EIO io error
|
||||
* @retval TLS_PARAM_STATUS_EPERM magic number error
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_init(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to load the system's default
|
||||
parameters
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note This function read user defined parameters first,
|
||||
if wrong, all the parameters restore factory settings
|
||||
*/
|
||||
void tls_param_load_factory_default(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to set one system parameter by its id
|
||||
*
|
||||
* @param[in] id param id,from TLS_PARAM_ID_SSID
|
||||
to (TLS_PARAM_ID_MAX - 1)
|
||||
* @param[in] *argv store parameters
|
||||
* @param[in] to_flash whether the parameter is written to flash,
|
||||
1:write to flash,0:only write memory
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK set success
|
||||
* @retval TLS_PARAM_STATUS_EINVALID invalid param
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_set(int id, void *argv, bool to_flash);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get one system parameter by its id.
|
||||
*
|
||||
* @param[in] id param id,from TLS_PARAM_ID_SSID
|
||||
to (TLS_PARAM_ID_MAX - 1)
|
||||
* @param[in] *argv store parameters
|
||||
* @param[in] from_flash whether the parameter is readed from flash,
|
||||
1 read from flash,0 read from memory
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK success
|
||||
* @retval TLS_PARAM_STATUS_EINVALID invalid param
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_get(int id, void *argv, bool from_flash);
|
||||
|
||||
/**
|
||||
* @brief This function is used to write parameter into flash
|
||||
*
|
||||
* @param[in] id param id,from TLS_PARAM_ID_ALL
|
||||
to (TLS_PARAM_ID_MAX - 1)
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK success
|
||||
* @retval TLS_PARAM_STATUS_EINVALID invalid param
|
||||
* @retval TLS_PARAM_STATUS_EIO read or write flash error
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_to_flash(int id);
|
||||
|
||||
/**
|
||||
* @brief This function is used to recovery the parameters from
|
||||
the backup area to the parameter area,and load them into ram
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_restore_param_from_backup(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to load default parametes into ram
|
||||
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK set success
|
||||
* @retval TLS_PARAM_STATUS_EINVALID parameter wrong
|
||||
* @retval TLS_PARAM_STATUS_EIO read or write falsh error
|
||||
*
|
||||
* @note This function read user defined parameters first,
|
||||
if wrong, all the parameters restore factory settings
|
||||
*/
|
||||
int tls_param_to_default(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to write user's parameters into the
|
||||
flash
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_save_user_default(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to modify user's default parameters,
|
||||
then write them into flash
|
||||
*
|
||||
* @param[in] *user_param
|
||||
*
|
||||
* @retval TLS_PARAM_STATUS_OK success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_save_user(struct tls_user_param *user_param);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get updp mode.(updp:update user
|
||||
default parameters)
|
||||
*
|
||||
* @param[in] None
|
||||
*
|
||||
* @retval update mode
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
u8 tls_param_get_updp_mode(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to set updp mode
|
||||
*
|
||||
* @param[in] mode
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_param_set_updp_mode(u8 mode);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get program param
|
||||
*
|
||||
* @param[in] *pBase pointer to save base address
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_get_program_param(u32 *pBase);
|
||||
|
||||
/**
|
||||
* @brief This function is used to set program base,image len,and
|
||||
checksum
|
||||
*
|
||||
* @param[in] base base address
|
||||
* @param[in] totallen total length of the image
|
||||
* @param[in] checksum checksum value of the image
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_param_set_program_param(u32 base, u32 totallen, u32 checksum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* WM_PARAM_H */
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file wm_wl_mbox.h
|
||||
*
|
||||
* @brief mailbox (mbox) APIs
|
||||
*
|
||||
* @author dave
|
||||
*
|
||||
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
#ifndef __TLS_WL_MBOX_H__
|
||||
#define __TLS_WL_MBOX_H__
|
||||
|
||||
#include "wm_type_def.h"
|
||||
#include "wm_osal.h"
|
||||
|
||||
/** max value of time out */
|
||||
#define SYS_ARCH_TIMEOUT 0xffffffffUL
|
||||
|
||||
/** pointer to the mailbox */
|
||||
typedef tls_os_queue_t * tls_mbox_t;
|
||||
|
||||
/**
|
||||
* @defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup MBOX_APIs MBOX APIs
|
||||
* @brief Software mailbox APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup MBOX_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Create a malibox
|
||||
*
|
||||
* @param[out] *mbox pointer to the mailbox
|
||||
* @param[in] size size of mailbox
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_mbox_new(tls_mbox_t *mbox, int size);
|
||||
|
||||
/**
|
||||
* @brief Check if an mbox is valid/allocated
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
*
|
||||
* @retval 0 invalid
|
||||
* @retval 1 valid
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_mbox_valid(tls_mbox_t mbox);
|
||||
|
||||
/**
|
||||
* @brief Sends a message to a mailbox
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
* @param[in] *msg pointer to the message to be post
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_mbox_post(tls_mbox_t mbox, void *msg);
|
||||
|
||||
/**
|
||||
* @brief Posts the msg to the mailbox.
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
* @param[in] *msg pointer to the message to be post
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note this function have to block until the "msg" is really posted.
|
||||
*/
|
||||
s8 tls_mbox_trypost(tls_mbox_t mbox, void *msg);
|
||||
|
||||
/**
|
||||
* @brief Waits for a message within specified time
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
* @param[out] **msg pointer to the message to be received
|
||||
* @param[in] timeout the specified time
|
||||
*
|
||||
* @retval SYS_ARCH_TIMEOUT time out
|
||||
* @retval other time of elapsed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
u32 tls_arch_mbox_fetch(tls_mbox_t mbox, void **msg, u32 timeout);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
/**
|
||||
* @file wm_wl_task.h
|
||||
*
|
||||
* @brief task APIs
|
||||
*
|
||||
* @author dave
|
||||
*
|
||||
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
#ifndef __TLS_WL_TASK_H__
|
||||
#define __TLS_WL_TASK_H__
|
||||
|
||||
#include "wm_type_def.h"
|
||||
#include "wm_wl_mbox.h"
|
||||
#include "wm_wl_timers.h"
|
||||
//#include "ithread.h"
|
||||
|
||||
#define TLS_TASK_START_PRIO 0
|
||||
#define TASK_WL_PRIO 9
|
||||
#define TASK_WL_PRIO_MAX 12
|
||||
#define TLS_SUPPLICANT_TASK_PRIO (TASK_WL_PRIO_MAX + 1)
|
||||
#define TLS_SUPPLICANT_TIMER_TASK_PRIO (TASK_WL_PRIO_MAX + 2)
|
||||
#define TLS_LWIP_TASK_PRIO (TASK_WL_PRIO_MAX + 3)
|
||||
#define TLS_SYS_TASK_PRIO (TASK_WL_PRIO_MAX + 5)
|
||||
#define TLS_HOSTIF_TASK_PRIO (TASK_WL_PRIO_MAX + 6)
|
||||
#define TLS_SPI_SCHEDULER_TASK_PRIO (TASK_WL_PRIO_MAX + 7)
|
||||
#define TLS_FWUP_TASK_PRIO (TASK_WL_PRIO_MAX + 8)
|
||||
#define TLS_HTTP_CLIENT_TASK_PRIO (TASK_WL_PRIO_MAX + 9)
|
||||
#define AP_SOCKET_S_TASK_PRIO (TASK_WL_PRIO_MAX + 10)
|
||||
#define TLS_UPNP_TASK_PRIO (TASK_WL_PRIO_MAX + 11)
|
||||
// #define TLS_ONESHOT_TASK_PRIO (TASK_WL_PRIO_MAX + 15)
|
||||
// #define TLS_ONESHOT_SPEC_TASK_PRIO (TASK_WL_PRIO_MAX + 16)
|
||||
|
||||
|
||||
#define TLS_MBOX_ALL_COUNT 8
|
||||
#define TLS_MBOX_ID_WL_TASK 0
|
||||
#define TLS_MBOX_ID_HOSTIF_TASK 1
|
||||
#define TLS_MBOX_ID_JDCLOUD_SERVER 2
|
||||
#define TLS_MBOX_ID_JDCLOUD_DATA 3
|
||||
#define TLS_MBOX_ID_UPNP_HD 4
|
||||
#define TLS_MBOX_ID_UPNP_COMMON 5
|
||||
#define TLS_MBOX_ID_UPNP_GENA 6
|
||||
#define TLS_MBOX_ID_UPNP_MINISERVER 7
|
||||
|
||||
#define TLS_TIMEO_ALL_COUONT 9
|
||||
#define TLS_TIMEO_ID_NULL 0
|
||||
#define TLS_TIMEO_ID_WL_TASK 1
|
||||
#define TLS_TIMEO_ID_HOSTIF_TASK 2
|
||||
#define TLS_TIMEO_ID_JDCLOUD_SERVER 3
|
||||
#define TLS_TIMEO_ID_JDCLOUD_DATA 4
|
||||
#define TLS_TIMEO_ID_UPNP_HD 5
|
||||
#define TLS_TIMEO_ID_UPNP_COMMON 6
|
||||
#define TLS_TIMEO_ID_UPNP_GENA 7
|
||||
#define TLS_TIMEO_ID_UPNP_MINISERVER 8
|
||||
|
||||
#define TLS_MSG_ALL_COUONT 9
|
||||
#define TLS_MSG_ID_TX_MGMT_CMPLT 0
|
||||
#define TLS_MSG_ID_MLME_TASK 1
|
||||
#define TLS_MSG_ID_UART_SENT_FREE 2
|
||||
#define TLS_MSG_ID_UART0_RX 3
|
||||
#define TLS_MSG_ID_HSPI_RX_CMD 4
|
||||
#define TLS_MSG_ID_HSPI_RX_DATA 5
|
||||
#define TLS_MSG_ID_HSPI_TX_DATA 6
|
||||
#define TLS_MSG_ID_TX_DATA_CMPLT 7
|
||||
#define TLS_MSG_ID_UART1_RX 8
|
||||
|
||||
/** pointer to the semaphore */
|
||||
typedef tls_os_sem_t * tls_sem_t;
|
||||
|
||||
/** Thread start routine */
|
||||
typedef void *(*start_routine)(void *arg);
|
||||
|
||||
/** message type of task */
|
||||
enum task_msg_type {
|
||||
TASK_MSG_TIMEOUT,
|
||||
TASK_MSG_UNTIMEOUT,
|
||||
TASK_MSG_CALLBACK_WITH_BLOCK,
|
||||
TASK_MSG_CALLBACK,
|
||||
TASK_MSG_CALLBACK_STATIC,
|
||||
TASK_MSG_NULL
|
||||
};
|
||||
|
||||
/** message of task */
|
||||
struct task_msg {
|
||||
enum task_msg_type type;
|
||||
tls_sem_t *sem;
|
||||
union {
|
||||
struct {
|
||||
start_routine function;
|
||||
void *ctx;
|
||||
} cb;
|
||||
struct {
|
||||
start_routine function;
|
||||
void *ctx;
|
||||
u8 cnt;
|
||||
} cbs;
|
||||
struct {
|
||||
u32 msecs;
|
||||
tls_timeout_handler h;
|
||||
void *arg;
|
||||
} tmo;
|
||||
} msg;
|
||||
};
|
||||
|
||||
/** task parameters */
|
||||
struct task_parameter{
|
||||
u8 task_id; /**< task ID */
|
||||
const char * name; /**< task name */
|
||||
u8 *stk_start; /**< start address of task stack */
|
||||
u32 stk_size; /**< size of task stack */
|
||||
u8 mbox_size; /**< size of mailbox */
|
||||
u8 mbox_id; /**< mailbox ID */
|
||||
u8 timeo_id; /**< timer ID */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Task_APIs Task APIs
|
||||
* @brief Software task APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Task_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Task initialized
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_task_init(void);
|
||||
|
||||
/**
|
||||
* @brief Running the task
|
||||
*
|
||||
* @param[in] *task_param pointer to the task parameters
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_task_run(struct task_parameter *task_param);
|
||||
|
||||
/**
|
||||
* @brief Running the callback function
|
||||
*
|
||||
* @param[in] *task_param pointer to the task parameters
|
||||
* @param[in] function the callback function
|
||||
* @param[in] *ctx parameter of the callback function
|
||||
* @param[in] block
|
||||
* @param[in] msg_id
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_task_callback_static(struct task_parameter *task_param,
|
||||
start_routine function, void *ctx, u8 block, u8 msg_id);
|
||||
|
||||
/**
|
||||
* @brief Running the callback function
|
||||
*
|
||||
* @param[in] *task_param pointer to the task parameters
|
||||
* @param[in] function the callback function
|
||||
* @param[in] *ctx parameter of the callback function
|
||||
* @param[in] block
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_task_callback(struct task_parameter *task_param,
|
||||
start_routine function, void *ctx, u8 block);
|
||||
|
||||
/**
|
||||
* @brief Add a timer to the task
|
||||
*
|
||||
* @param[in] *task_param pointer to the task parameters
|
||||
* @param[in] msecs timer value
|
||||
* @param[in] h the callback function
|
||||
* @param[in] *arg parameter of the callback function
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_task_add_timeout(struct task_parameter *task_param, u32 msecs,
|
||||
tls_timeout_handler h, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Stop or delay the timer to expire.
|
||||
*
|
||||
* @param[in] *task_param pointer to the task parameters
|
||||
* @param[in] h the callback function
|
||||
* @param[in] *arg parameter of the callback function
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_task_untimeout(struct task_parameter *task_param,
|
||||
tls_timeout_handler h, void *arg);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @file wm_wl_timers.h
|
||||
*
|
||||
* @brief task APIs
|
||||
*
|
||||
* @author dave
|
||||
*
|
||||
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
#ifndef __TLS_WL_TIMERS_H__
|
||||
#define __TLS_WL_TIMERS_H__
|
||||
|
||||
#include "wm_type_def.h"
|
||||
#include "wm_wl_mbox.h"
|
||||
|
||||
/** callback function of time out */
|
||||
typedef void (* tls_timeout_handler)(void *arg);
|
||||
|
||||
/**
|
||||
* @defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Timer_APIs Timer APIs
|
||||
* @brief Software timer APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Timer_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Create a one-shot timer (aka timeout)
|
||||
*
|
||||
* @param[in] timeo_assigned timer NO. by assigned
|
||||
* @param[in] msecs time in milliseconds after that the timer should expire
|
||||
* @param[in] handler callback function that would be called by the timeout
|
||||
* @param[in] *arg callback argument that would be passed to handler
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note While waiting for a message using sys_timeouts_mbox_fetch()
|
||||
*/
|
||||
void tls_timeout_p(u8 timeo_assigned, u32 msecs, tls_timeout_handler handler, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Go through timeout list (for this task only) and remove the first
|
||||
* matching entry, even though the timeout has not been triggered yet
|
||||
*
|
||||
* @param[in] timeo_assigned timer NO. by assigned
|
||||
* @param[in] handler callback function that would be called by the timeout
|
||||
* @param[in] *arg callback argument that would be passed to handler
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_untimeout_p(u8 timeo_assigned, tls_timeout_handler handler, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Wait (forever) for a message to arrive in an mbox.
|
||||
* While waiting, timeouts are processed
|
||||
*
|
||||
* @param[in] timeo_assigned timer NO. by assigned
|
||||
* @param[in] mbox the mbox to fetch the message from
|
||||
* @param[out] **msg the place to store the message
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_timeouts_mbox_fetch_p(u8 timeo_assigned, tls_mbox_t mbox, void **msg);
|
||||
|
||||
/**
|
||||
* @brief Initialize the timer
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval 0 success
|
||||
* @retval other failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_timer_init(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user