blob: fcf872d8ae8db091c1e24ffbdc1c696ee13e6d1e [file] [log] [blame]
/**
* @file netotherapi.h
* @brief Public APIs of Sanechips , linux network external interface
*
* Copyright (C) 2017 Sanechips Technology Co., Ltd.
* @author Linxu Gebin
* @defgroup si_id Sanechips
*
* 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.
*************************************************************************
*/
#ifndef __NETOTHERAPI_H__
#define __NETOTHERAPI_H__
#include "zxic_list.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/*******************************************************************************
* Macro definitions *
******************************************************************************/
#define WAKE_LOCK_PATH "/sys/power/wake_lock"
#define WAKE_UNLOCK_PATH "/sys/power/wake_unlock"
#define PROC_IF_STATISTIC "/proc/net/dev"
#define TXBYTE 0 //·¢ËÍÊý¾Ý
#define TXPACKET 1
#define RXBYTE 2 //½ÓÊÕÊý¾Ý
#define RXPACKET 3
#define TXERR 4
#define TXDROP 5
#define RXERR 6
#define RXDROP 7
#define PC_MAX_NUM 100
#define DEV_NAME_LEN 50
#define TIMER_GETHOSTBYNAME_ID 62
#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
/* Used to retry syscalls that can return EINTR. */
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp) ({ \
typeof (exp) _rc; \
do{ \
_rc = (exp); \
}while((_rc == -1) && (errno == EINTR)); \
_rc; })
#endif
/*******************************************************************************
* Type definitions *
******************************************************************************/
struct pc_info {
unsigned char mac_addr[6];
char dev_name[DEV_NAME_LEN];
};
struct pc_node {
unsigned int num;
struct pc_info info[PC_MAX_NUM];
};
/**
* @brief ÄÚÍøÐÅÏ¢
* @param mac mac µØÖ·
* @param ip ip µØÖ·
* @param hostname Ö÷»úÃû
* @param dev_name É豸Ãû
* @param time_remain µ±Ç°Ê±¼äµ½ÉÏÒ»¸üиÃÉ豸ÐÅÏ¢¼ä¸ôʱ¼ä
* @param time_last ×î½üÒ»´Î¸üÐÂʱ¼äµã
* @note ÎÞ
*/
typedef struct LAN_INFO {
unsigned char mac[6];
unsigned long ip;
char host_name[32];
char dev_name[32];
unsigned long time_remain;
unsigned long time_last;
} LAN_INFO_t;
/**
* @brief ÄÚÍøÐÅÏ¢Á´±í
* @param list_head Á´±íÍ·½Úµã
* @param lan_info lÄÚÍøÐÄÏ¢
* @note ÎÞ
*/
typedef struct LAN_INFO_LIST {
struct list_head list;
LAN_INFO_t lan_info;
} LAN_INFO_LIST_t;
/**
* @brief dhcp server´æ´¢µÄleaseÎļþ½á¹¹Ìå
* @param expires expires
* @param ip ip µØÖ·
* @param mac mac µØÖ·
* @param host_nameÖ÷»úÃû
* @param pad
*/
typedef struct _DHCPOFFERADDRNET {
unsigned long expires;
unsigned long ip;
unsigned char mac[6];
unsigned char host_name[20];
unsigned char pad[2];
} DHCPOFFERADDRNET;
/**
* @brief dhcp ÐÅÏ¢Á´±í
* @param list Á´±íÍ·½Úµã
* @param dhcp_info dhcp ÐÅÏ¢
*/
typedef struct _DHCPOFFERADDR_LIST {
struct list_head list;
DHCPOFFERADDRNET dhcp_info;
} DHCPOFFERADDR_LIST_t;
/**
* @brief dhcp gethostbynameÐÅÏ¢
* @param time ³¬Ê±Ê±¼ä£¬µ¥Î»ÎªºÁÃë
* @param ¶ÓÁкÅ
*/
struct gethostbyname_info{
int time;
char name[HOSTNAME_LEN];
int msg_id;
};
/*******************************************************************************
* Global function declarations *
******************************************************************************/
/**
* @brief ´Ódhcpd.leasesÎļþÖлñÈ¡dhcpÐÅÏ¢
* @param dhcp_list_info dhcp ÐÅÏ¢Á´±í
* @return ³É¹¦ ·µ»Ø 0, ʧ°Ü·µ»Ø-1
*/
int zte_get_mac_list_from_lease(struct list_head *dhcp_list_info);
/**
* @brief É豸ÐÅÏ¢
* @param mypc_node É豸ÐÅÏ¢Á´±í
* @param info information
* @return ³É¹¦ ·µ»Ø 0, ʧ°Ü·µ»Ø-1
*/
int get_dev_list(struct pc_node* mypc_node);
/**
* @brief ±£´æÐÅÏ¢µ½Îļþ
* @param filename ÎļþÃû
* @param info ÐèÒª±£´æµÄÐÅÏ¢
* @return ÎÞ
*/
void save_file(char *filename, char* info);
/**
* @brief дÐÅÏ¢µ½Îļþ
* @param filename ÎļþÃû
* @param info ÐèҪдµÄÐÅÏ¢
* @return ÎÞ
*/
void file_write(char *filename, char *info);
/**
* @brief ÊÍ·ÅdhcpÐÅÏ¢Á´±í
* @param dhcp_info_list dhcpÁ´±íÍ·½áµã
* @return ÎÞ
*/
void free_dhcp_list(struct list_head * dhcp_info_list);
/**
* @brief ÊÍ·ÅÄÚÍøÐÅÏ¢Á´±í
* @param dhcp_info_list ÄÚÍøÐÅÏ¢Á´±íÍ·½áµã
* @return ÎÞ
*/
void free_laninfo_list(struct list_head * dhcp_info_list);
/**
* @brief »ñÈ¡É豸ÐÅÏ¢
* @param interface ÍøÂçÉ豸Ãû
* @param type Êý¾ÝÀàÐÍ
* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·Å»Ø-1
*/
int getIfStatistic(char *interface, int type, unsigned long long *result_data);
/**
* @brief »ñÈ¡wakelockËø
* @param lockId wakelockËøID
* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£»
*/
int set_wake_lock(const char *lockId);
/**
* @brief »ñÈ¡wakelock³¬Ê±Ëø
* @param lockId wakelockËøID
* @param interval ³¬Ê±Ê±¼ä£¬µ¥Î»: Ãë
* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£»
*/
int set_wake_lock_timeout(const char *lockId, unsigned long interval);
/**
* @brief ÊÍ·ÅwakelockËø
* @param lockId wakelockËøID
* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1£»
*/
int set_wake_unlock(const char *lockId);
int get_lan_info_list(struct list_head *file_list_info);
/**
* @brief ÉêÇëÄÚ´æ
* @param size ÉêÇëÄÚ´æ´óС
* @param is_assert£¬ÉêÇëʧ°ÜÊÇ·ñassert
* @return ÉêÇë³É¹¦·µ»ØÉêÇëÄÚ´æµØÖ·£»Ê§°Ü·µ»ØNULL
*/
void *safe_malloc(int size, BOOL is_assert);
unsigned long time_sec();
/**
* @brief »ñȡָ¶¨Ïß³ÌÃûµÄpidºÅ
* @param pidNameΪ½ø³ÌÃû
* @return ³É¹¦·µ»Ø½ø³ÌºÅpid_tÀàÐÍÖ¸Õë
* @note µ÷Óøú¯Êý»ñÈ¡·µ»ØÖµ£¬Ê¹ÓúóÒ»¶¨ÒªÊͷŸÃÄÚ´æ¿Õ¼ä
*/
pid_t* find_pid_by_name(char *pidName);
/**
* @brief ¾ßÓг¬Ê±´¦ÀíµÄgethostbyname
* @param name url
* @param time ³¬Ê±Ê±³¤,µ¥Î»:Ãë, 0¾ÍÊDZê×¼µÄgethostbyname¹¦ÄÜ
* @return hostÐÅÏ¢
* @Note: ͬһ½ø³ÌͬʱֻÄܵ÷ÓÃÒ»´Î¸Ã½Ó¿Ú
*/
struct hostent *gethostbyname_t(const char *name, int time);
/**
* @±¾µØ¼¤»î»ñÈ¡dns½Ó¿Ú£¬²»ÒÀÀµÂ·ÓÉ£¬·µ»ØÖµÎªu32ÀàÐÍipµØÖ·
*/
unsigned long gethostbyname_l(char *hostname,char* dev_name);
#endif
#endif /* __NETOTHERAPI_H__ */