www.pudn.com > MT7681_IoT_Package_v0.02.rar > iot_api.h, change:2014-01-28,size:4920b


#include "config.h"

#ifndef _IOT_API_H_
#define _IOT_API_H_


/******************************************************************************
* MODULE NAME:     iot_api.h
* PROJECT CODE:    __MT7681__
* DESCRIPTION:     
* DESIGNER:        
* DATE:            Jan 2014
*
* SOURCE CONTROL:
*
* LICENSE:
*     This source code is copyright (c) 2014 Mediatek. Inc.
*     All rights reserved.
*
* REVISION     HISTORY:
*   V0.0.1     Jan 2014    - Initial Version V0.0.1
*
*
* SOURCE:
* ISSUES:
*    First Implementation.
* NOTES TO USERS:
*
******************************************************************************/

struct GNU_PACKED ipv4hdr {
	
	UINT8	version_ihl;
	UINT8	tos;
	UINT16	tot_len;
	UINT16	id;
	UINT16	frag_off;
	UINT8	ttl;
	UINT8	protocol;
	UINT8	check[2];
	UINT32	saddr;
	UINT32	daddr;
	/*The options start here. */
};

struct GNU_PACKED udphdr {
	UINT16	source_port;
	UINT16	dest_port;
	UINT16	len;
	UINT8	check[2];
};

struct GNU_PACKED udppseudohdr {
	UINT32	saddr;
	UINT32	daddr;
	UINT8 ttl;
	UINT8 protocol;
	UINT16 udpdatalen;
	
	UINT16	source_port;
	UINT16	dest_port;
	UINT16	len;
	UINT8	check[2];
};

/*for record AT cmd Option count*/
#define MAX_OPTION_COUNT 10


/*type define*/
//typedef unsigned int UINT_32;
//typedef unsigned short UINT_16;
typedef unsigned char UINT_8;
typedef char TYPE;

#define MAC_ADDR_LEN			6
#define DESC_MAX_LEN			32
#define UART_MAX_DATALEN		1024
#define PACKAGE_BUFFER_MAX_LEN	1600
#define IOT_MAGIC_NUMBER		0x76814350
#define DEFAULT_SESSION_ID		0xFFFFFFFF

/*protocol related define*/

typedef struct GNU_PACKED t_IoTCtrlProtocolHeader
{
	UINT_32 Magic;                    //protocol magic number
	UINT_8 ReceiveMAC[MAC_ADDR_LEN];  //receive mac address
	UINT_8 SendMAC[MAC_ADDR_LEN];     //sender mac address
	UINT_32 SessionID;                //reserved
	UINT_16 Sequence;                 //sequence number
	UINT_16 Flag:4;                   //reserved
	UINT_16 Type:4;                   //command type. 0: management command 1: function command
	UINT_16 SubType:8;	              //subtype
} IoTCtrlProtocolHeader;

typedef enum t_CommandType
{
	MANAGEMENT,
	FUNCTION,
	TYPE_MAX
}CommandType;

typedef enum t_ManagementCommand
{
	QUERY_CAPAB_REQUEST = 1,
	QUERY_CAPAB_RESPONSE,
	CONTROL_CLIENT_OFFLINE_REQUEST,
	CONTROL_CLIENT_OFFLINE_RESPONSE,
	MANAGEMENT_COMMAND_MAX
}ManagementCommand;

typedef enum t_FunctionCommand
{
	GPIO_SET_REQUEST = 1,
	GPIO_SET_RESPONSE,
	GPIO_GET_REQUEST,
	GPIO_GET_RESPONSE,
	UART_SET_REQUEST,
	UART_SET_RESPONSE,
	UART_GET_REQUEST,
	UART_GET_RESPONSE,
	PWM_SET_REQUEST,
	PWM_SET_RESPONSE,
	PWM_GET_REQUEST,
	PWM_GET_RESPONSE,
	FUNCTION_COMMAND_MAX
}FunctionCommand;

typedef enum t_DataType
{
	STATUS,
	CLIENT_CAPABILITY,
	UART_INFORMATION,
	GPIO_INFORMATION,
	PWM_INFORMATION
}DataType;

/*Control Data information*/
typedef struct GNU_PACKED t_DataHeader
{
	UINT_16 Type;
	UINT_16 Length;
}DataHeader;

typedef struct GNU_PACKED t_Status
{
	UINT_8 StatusCode;
}Status;


typedef struct GNU_PACKED t_UART_Information
{
	UINT_8 Data[UART_MAX_DATALEN];
}UART_Information;

typedef struct GNU_PACKED t_GPIO_Information
{
	UINT_32 GPIO_List;
    UINT_32 GPIO_Value;
}GPIO_Information;

typedef struct GNU_PACKED t_PWM_Information
{
	UINT_16 RedLevel;
	UINT_16 GreenLevel;
	UINT_16 BlueLevel;
}PWM_Information;

typedef struct GNU_PACKED t_ClientCapability
{
	UINT_16 VendorNameLen;
	UINT_8 VendorName[DESC_MAX_LEN];
	UINT_16 ProductTypeLen;
	UINT_8 ProductType[DESC_MAX_LEN];
	UINT_16 ProductNameLen;
	UINT_8 ProductName[DESC_MAX_LEN];
}ClientCapability;


typedef struct GNU_PACKED IoTHardwareRresource
{
	UINT_32 GPIO_Rresource;
	UINT_32 UART_Rresource;
	UINT_32 LED_Rresource;
	INT_8 GPIO_Count;
	INT_8 UART_Count;
	INT_8 LED_Count;
	
} t_IoTHardwareRresource;
//#define UART_SWITCH_TO_PWM

typedef struct GNU_PACKED IoTHardwareStatus
{
	
	UINT_16 RedLevel;
	UINT_16 GreenLevel;
	UINT_16 BlueLevel;
	
}t_IoTHardwareStatus;

typedef struct GNU_PACKED t_IoTPacketInfo
{
	UINT_32 SessionID;
	UINT_16 Sequence;
	UCHAR ReceiveMAC[6];
	UCHAR SendMAC[6];
	
} IoTPacketInfo;

extern UCHAR gCurrentAddress[MAC_ADDR_LEN];	


VOID IoT_Cmd_LinkDown(UINT8 reason);


VOID MlmeDeauthReqAction(IN PUCHAR pDA_Addr,
						 IN PUCHAR pBSSID_Addr,
						 IN USHORT Reason);

int IoT_gpio_output(int gpio_num,  int output);

int IoT_gpio_input(int gpio_num,  int *input);

int IoT_uart_output(UINT_8 *msg, int count);

int IoT_uart_input(UINT_8 *msg, int count);

int IoT_led_pwm(int led_num, int brightness);

int IoT_build_app_response_header(
			PUCHAR buffer,
			UINT_8 ProtoType, 
			UINT_8 ProtoSubType, 
			UINT_16 DataType, 
			UINT_16 DataLen, 
			struct t_IoTPacketInfo *PacketInfo);

#define MAX_TCP_DATA 16
#define MAX_IP_STRING_LEN 16


#if !CFG_SUPPORT_TCPIP
void IoT_build_send_udp_packet(
			PUCHAR pSrcAddr, 
			PUCHAR pDstAddr,
			UINT16 SrcPort,
			UINT16 DstPort,
			PUCHAR pPayload, 
			UINT16  PayloadLen);
#endif

#endif