Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources

This commit is contained in:
2026-07-06 11:30:13 +08:00
commit e76462eeb7
3451 changed files with 1415300 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#ifndef _HUGEIC_DHCPD_H_
#define _HUGEIC_DHCPD_H_
#ifdef __cplusplus
extern "C" {
#endif
struct dhcpd_param {
uint32 lease_time; /*unit: seconds*/
uint32 start_ip, end_ip; /*network byteorder*/
uint32 netmask; /*network byteorder*/
uint32 router; /*network byteorder*/
uint32 dns1; /*network byteorder*/
uint32 dns2; /*network byteorder*/
};
struct dhcpd_leaseinfo {
uint32 ip;
uint8 mac[6];
};
int32 dhcpd_get_lease_list(struct dhcpd_leaseinfo *leaseslist, int32 list_size);
uint32 dhcpd_get_lease_ip(uint8 *mac);
void dhcpd_ip_inactive(uint8 *mac);
int32 dhcpd_start(char *ifname, struct dhcpd_param *param);
void dhcpd_stop(void);
void dhcpd_flush(void);
void dhcpd_set_dns(uint32 dns1, uint32 dns2);
void dhcpd_dump_ippool(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,125 @@
/**@file eloop.h
* @author 何凱帆
* @brief 基於socket的event loop服務
* @details 提供基於socket的event loop服務
*/
#ifndef _ELOOP_H_
#define _ELOOP_H_
#include "list.h"
#include "lwip/api.h"
#include "lwip/sockets.h"
#define EVT_HDL void *
#ifndef SOCK_HDL
#define SOCK_HDL int
#endif
#define EVENT_READ 0
#define EVENT_WRITE 1
#define EVENT_F_DISABLED 0
#define EVENT_F_NOACTION 0
#define EVENT_F_ENABLED 1
#define EVENT_F_REMOVE 2
#define EVENT_F_ONESHOT 4
#define EVENT_F_RUNNING 8
#define ELOOP_WAKEUP_BY_LOOPBACK 1
#define EVENT_TIME 1
#define EVENT_FD 2
#define EVENT_ALWAYS 3
#define EVENT_SOFT_QUEUE 4
struct eloop_timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
typedef struct timeval time_ref;
typedef unsigned int eloop_time_ref;
typedef void (*event_callback)(EVT_HDL e, void* d);
struct time_event {
eloop_time_ref fire;
int ival;
};
struct fd_event {
SOCK_HDL fd;
int write; // 0 = read, 1 = write
};
struct eloop_state {
struct list_head times;
struct list_head fds;
struct list_head always;
struct list_head wait;
int end_loop;
};
struct event {
struct list_head list;
event_callback func;
void* data;
int type;
int flags;
union {
struct time_event time;
struct fd_event fd;
} ev;
};
//#include "linux_ktime.h"
void eloop_resched_event(EVT_HDL ev, eloop_time_ref* tr);
void eloop_remove_event(EVT_HDL ev);
void eloop_set_event_interval(EVT_HDL ev, int msec);
void eloop_set_event_enabled(EVT_HDL ev, int enabled);
int eloop_get_event_enabled(EVT_HDL ev);
EVT_HDL eloop_add_timer(int msec, unsigned int flags, event_callback f, void* d);
EVT_HDL eloop_add_alarm(eloop_time_ref t, unsigned int flags, event_callback f, void* d);
EVT_HDL eloop_add_fd(SOCK_HDL fd, int write, unsigned int flags, event_callback f, void* d);
EVT_HDL eloop_add_always(unsigned int flags, event_callback f, void* d);
void set_event_time(void *d,int msec);
void eloop_exit(void);
void eloop_init(void);
void user_eloop_run();
static void eloop_wakeup(void);
void time_now(eloop_time_ref* tr);
unsigned int get_time_now();
//int gettimeofday(struct timeval *tv,void *ignore);
#endif /* _ELOOP_H_ */

View File

@@ -0,0 +1,30 @@
#ifndef __ETH_MDIO_BUS_H_
#define __ETH_MDIO_BUS_H_
struct netdev;
/*
* The Bus class for PHYs. Devices which provide access to
* PHYs should register using this structure
*/
struct ethernet_mdio_bus {
struct dev_obj dev;
void *priv;
int (*read)(void *priv, uint16 phy_addr, uint16 regnum);
int (*write)(void *priv, uint16 phy_addr, uint16 regnum, uint16 val);
/*
* A lock to ensure that only one thing can read/write
* the MDIO bus at a time
*/
// struct mutex mdio_lock;
};
int32 eth_mdio_bus_attach(uint32 dev_id, struct ethernet_mdio_bus *p_mii_bus);
int32 eth_mdio_bus_open(struct ethernet_mdio_bus *p_mii_bus, struct netdev *p_netdev);
int32 eth_mdio_bus_close(struct ethernet_mdio_bus *p_mii_bus);
int32 eth_mdio_bus_write(struct ethernet_mdio_bus *p_mii_bus, uint16 phy_addr, uint16 reg_addr, uint16 data);
int32 eth_mdio_bus_read(struct ethernet_mdio_bus *p_mii_bus, uint16 phy_addr, uint16 reg_addr);
#endif

View File

@@ -0,0 +1,386 @@
/**
******************************************************************************
* @file sdk/include/lib/ethernet_phy/eth_phy.h
* @author HUGE-IC Application Team
* @version V1.0.0
* @date 10-10-2018
* @brief Framework and drivers for configuring and reading different PHYs
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2018 HUGE-IC</center></h2>
*
*
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ETH_PHY_H__
#define __ETH_PHY_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "ethtool.h"
#include "mii.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @weakgroup NETWORK_PHY
* @{
*/
/** @defgroup NETWORK_PHY_Exported_Constants Exported Constants
* @{
*/
#define PHY_ADAPTIVE_ADDR -1
#define PHY_INIT_TIMEOUT 100000
#define PHY_STATE_TIME 1
#define PHY_FORCE_TIMEOUT 10
#define PHY_AN_TIMEOUT 10
#define PHY_MAX_ADDR 32
#define PHY_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
SUPPORTED_10baseT_Full | \
SUPPORTED_100baseT_Half | \
SUPPORTED_100baseT_Full | \
SUPPORTED_Autoneg | \
SUPPORTED_TP | \
SUPPORTED_MII)
#define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
SUPPORTED_1000baseT_Half | \
SUPPORTED_1000baseT_Full)
/**
* @}
*/
/** @defgroup NETWORK_PHY_Exported_Typedefs Exported Typedefs
* @{
*/
struct netdev;
struct ethernet_phy_device;
/* PHY state machine states:
*
* DOWN: PHY device and driver are not ready for anything. probe
* should be called if and only if the PHY is in this state,
* given that the PHY device exists.
* - PHY driver probe function will, depending on the PHY, set
* the state to STARTING or READY
*
* STARTING: PHY device is coming up, and the ethernet driver is
* not ready. PHY drivers may set this in the probe function.
* If they do, they are responsible for making sure the state is
* eventually set to indicate whether the PHY is UP or READY,
* depending on the state when the PHY is done starting up.
* - PHY driver will set the state to READY
* - start will set the state to PENDING
*
* READY: PHY is ready to send and receive packets, but the
* controller is not. By default, PHYs which do not implement
* probe will be set to this state by phy_probe(). If the PHY
* driver knows the PHY is ready, and the PHY state is STARTING,
* then it sets this STATE.
* - start will set the state to UP
*
* PENDING: PHY device is coming up, but the ethernet driver is
* ready. phy_start will set this state if the PHY state is
* STARTING.
* - PHY driver will set the state to UP when the PHY is ready
*
* UP: The PHY and attached device are ready to do work.
* Interrupts should be started here.
* - timer moves to AN
*
* AN: The PHY is currently negotiating the link state. Link is
* therefore down for now. phy_timer will set this state when it
* detects the state is UP. config_aneg will set this state
* whenever called with phydev->autoneg set to AUTONEG_ENABLE.
* - If autonegotiation finishes, but there's no link, it sets
* the state to NOLINK.
* - If aneg finishes with link, it sets the state to RUNNING,
* and calls adjust_link
* - If autonegotiation did not finish after an arbitrary amount
* of time, autonegotiation should be tried again if the PHY
* supports "magic" autonegotiation (back to AN)
* - If it didn't finish, and no magic_aneg, move to FORCING.
*
* NOLINK: PHY is up, but not currently plugged in.
* - If the timer notes that the link comes back, we move to RUNNING
* - config_aneg moves to AN
* - phy_stop moves to HALTED
*
* FORCING: PHY is being configured with forced settings
* - if link is up, move to RUNNING
* - If link is down, we drop to the next highest setting, and
* retry (FORCING) after a timeout
* - phy_stop moves to HALTED
*
* RUNNING: PHY is currently up, running, and possibly sending
* and/or receiving packets
* - timer will set CHANGELINK if we're polling (this ensures the
* link state is polled every other cycle of this state machine,
* which makes it every other second)
* - irq will set CHANGELINK
* - config_aneg will set AN
* - phy_stop moves to HALTED
*
* CHANGELINK: PHY experienced a change in link state
* - timer moves to RUNNING if link
* - timer moves to NOLINK if the link is down
* - phy_stop moves to HALTED
*
* HALTED: PHY is up, but no polling or interrupts are done. Or
* PHY is in an error state.
*
* - phy_start moves to RESUMING
*
* RESUMING: PHY was halted, but now wants to run again.
* - If we are forcing, or aneg is done, timer moves to RUNNING
* - If aneg is not done, timer moves to AN
* - phy_stop moves to HALTED
*/
enum ethernet_phy_state {
ETH_PHY_DOWN = 0,
ETH_PHY_STARTING,
ETH_PHY_READY,
ETH_PHY_PENDING,
ETH_PHY_UP,
ETH_PHY_AN,
ETH_PHY_RUNNING,
ETH_PHY_NOLINK,
ETH_PHY_FORCING,
ETH_PHY_CHANGELINK,
ETH_PHY_HALTED,
ETH_PHY_RESUMING
};
/* struct phy_driver: Driver structure for a particular PHY type
*
* phy_id: The result of reading the UID registers of this PHY
* type, and ANDing them with the phy_id_mask. This driver
* only works for PHYs with IDs which match this field
* name: The friendly name of this PHY type
* phy_id_mask: Defines the important bits of the phy_id
* features: A list of features (speed, duplex, etc) supported
* by this PHY
* flags: A bitfield defining certain other features this PHY
* supports (like interrupts)
*
* The drivers must implement config_aneg and read_status. All
* other functions are optional. Note that none of these
* functions should be called from interrupt time. The goal is
* for the bus read/write functions to be able to block when the
* bus transaction is happening, and be freed up by an interrupt
* (The MPC85xx has this ability, though it is not currently
* supported in the driver).
*/
struct ethernet_phy_driver {
uint32 features;
/*
* Called to initialize the PHY,
* including after a reset
*/
int (*config_init)(struct ethernet_phy_device *phydev);
/*
* Called during discovery. Used to set
* up device-specific structures, if any
*/
// int (*probe)(struct ethernet_phy_device *phydev);
/* PHY Power Management */
// int (*suspend)(struct ethernet_phy_device *phydev);
// int (*resume)(struct ethernet_phy_device *phydev);
/*
* Configures the advertisement and resets
* autonegotiation if phydev->autoneg is on,
* forces the speed to the current settings in phydev
* if phydev->autoneg is off
*/
int (*config_aneg)(struct ethernet_phy_device *phydev);
/* Determines the negotiated speed and duplex */
int (*read_status)(struct ethernet_phy_device *phydev);
/* Clears any pending interrupts */
// int (*ack_interrupt)(struct ethernet_phy_device *phydev);
/* Enables or disables interrupts */
// int (*config_intr)(struct ethernet_phy_device *phydev);
/*
* Checks if the PHY generated an interrupt.
* For multi-PHY devices with shared PHY interrupt pin
*/
// int (*did_interrupt)(struct ethernet_phy_device *phydev);
/* Clears up any memory if needed */
// void (*remove)(struct ethernet_phy_device *phydev);
/* Returns true if this is a suitable driver for the given
* phydev. If NULL, matching is based on phy_id and
* phy_id_mask.
*/
// int (*match_phy_device)(struct ethernet_phy_device *phydev);
/* Handles ethtool queries for hardware time stamping. */
// int (*ts_info)(struct ethernet_phy_device *phydev, struct ethtool_ts_info *ti);
/* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */
// int (*hwtstamp)(struct ethernet_phy_device *phydev, struct ifreq *ifr);
/*
* Requests a Rx timestamp for 'skb'. If the skb is accepted,
* the phy driver promises to deliver it using netif_rx() as
* soon as a timestamp becomes available. One of the
* PTP_CLASS_ values is passed in 'type'. The function must
* return true if the skb is accepted for delivery.
*/
// bool (*rxtstamp)(struct ethernet_phy_device *dev, struct sk_buff *skb, int type);
/*
* Requests a Tx timestamp for 'skb'. The phy driver promises
* to deliver it using skb_complete_tx_timestamp() as soon as a
* timestamp becomes available. One of the PTP_CLASS_ values
* is passed in 'type'.
*/
// void (*txtstamp)(struct ethernet_phy_device *dev, struct sk_buff *skb, int type);
/* Some devices (e.g. qnap TS-119P II) require PHY register changes to
* enable Wake on LAN, so set_wol is provided to be called in the
* ethernet driver's set_wol function. */
// int (*set_wol)(struct ethernet_phy_device *dev, struct ethtool_wolinfo *wol);
/* See set_wol, but for checking whether Wake on LAN is enabled. */
// void (*get_wol)(struct ethernet_phy_device *dev, struct ethtool_wolinfo *wol);
};
/* phy_device: An instance of a PHY
*
* p_emac_dev: Pointer to the bus this PHY is on
* phy_id: UID for this device found during discovery
* state: state of the PHY for management purposes
* addr: Bus address of PHY
* link_timeout: The number of timer firings to wait before the
* giving up on the current attempt at acquiring a link
* adjust_link: Callback for the enet controller to respond to
* changes in the link state.
* adjust_state: Callback for the enet driver to respond to
* changes in the state machine.
*
* speed, duplex, pause, supported, advertising, and
* autoneg are used like in mii_if_info
*
* interrupts currently only supports enabled or disabled,
* but could be changed in the future to support enabling
* and disabling specific interrupts
*
* Contains some infrastructure for polling and interrupt
* handling, as well as handling shifts in PHY hardware state
*/
struct ethernet_phy_device {
struct dev_obj dev;
/* Bus address of the PHY (0-31) */
int16 addr;
/* phy driver pointer */
struct ethernet_phy_driver *drv;
struct ethernet_mdio_bus *bus;
struct netdev *ndev;
uint32 phy_id;
enum ethernet_phy_state state;
/*
* forced speed & duplex (no autoneg)
* partner speed & duplex & pause (autoneg)
*/
int16 speed;
int16 duplex;
int16 pause;
int16 asym_pause;
/* The most recently read link state */
int16 link;
/* Union of PHY and Attached devices' supported modes */
/* See mii.h for more info */
uint32 supported;
uint32 advertising;
uint32 autoneg;
uint32 link_timeout;
/* last state */
int16 last_speed;
int16 last_duplex;
int16 last_link;
//os_task_t task;
};
/**
* @}
*/
/** @defgroup NETWORK_PHY_Exported_Functions Exported Functions
* @{
*/
extern struct ethernet_phy_driver genphy_driver;
uint16 phy_read(struct ethernet_phy_device *phydev, uint16 reg);
void phy_write(struct ethernet_phy_device *phydev, uint16 reg, uint16 val);
void eth_phy_device_create(struct ethernet_phy_device *dev);
uint8 eth_get_phy_device(struct ethernet_phy_device *dev);
int32 eth_phy_connect_direct(struct ethernet_phy_device *phydev);
uint8 eth_phy_start_aneg(struct ethernet_phy_device *phydev);
int genphy_config_init(struct ethernet_phy_device *phydev);
int genphy_restart_aneg(struct ethernet_phy_device *phydev);
int genphy_config_aneg(struct ethernet_phy_device *phydev);
int genphy_update_link(struct ethernet_phy_device *phydev);
int genphy_read_status(struct ethernet_phy_device *phydev);
void eth_phy_state_machine(struct ethernet_phy_device *phydev);
void eth_phy_start_machine(struct ethernet_phy_device *phydev);
int32 eth_phy_open(struct ethernet_phy_device *phydev, struct ethernet_mdio_bus *mdio_bus, struct netdev *ndev);
void eth_phy_close(struct ethernet_phy_device *phydev);
void eth_phy_attach(uint32 dev_id, struct ethernet_phy_device *phydev);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif //__ETH_PHY_H__
/*************************** (C) COPYRIGHT 2018 HUGE-IC ***** END OF FILE *****/

View File

@@ -0,0 +1,166 @@
/**
******************************************************************************
* @file sdk/include/lib/ethernet_phy/ethtool.h
* @author HUGE-IC Application Team
* @version V1.0.0
* @date 10-10-2018
* @brief Defines for Linux ethtool
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2018 HUGE-IC</center></h2>
*
*
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ETHTOOL_H__
#define __ETHTOOL_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @weakgroup NETWORK
* @{
*/
/** @defgroup NETWORK_ETHTOOL Ethtool
* @brief Defines for Linux ethtool
* @{
*/
/** @defgroup NETWORK_ETHTOOL_Exported_Constants Exported Constants
* @{
*/
/* Indicates what features are supported by the interface. */
#define SUPPORTED_10baseT_Half (1 << 0)
#define SUPPORTED_10baseT_Full (1 << 1)
#define SUPPORTED_100baseT_Half (1 << 2)
#define SUPPORTED_100baseT_Full (1 << 3)
#define SUPPORTED_1000baseT_Half (1 << 4)
#define SUPPORTED_1000baseT_Full (1 << 5)
#define SUPPORTED_Autoneg (1 << 6)
#define SUPPORTED_TP (1 << 7)
#define SUPPORTED_AUI (1 << 8)
#define SUPPORTED_MII (1 << 9)
#define SUPPORTED_FIBRE (1 << 10)
#define SUPPORTED_BNC (1 << 11)
#define SUPPORTED_10000baseT_Full (1 << 12)
#define SUPPORTED_Pause (1 << 13)
#define SUPPORTED_Asym_Pause (1 << 14)
#define SUPPORTED_2500baseX_Full (1 << 15)
#define SUPPORTED_Backplane (1 << 16)
#define SUPPORTED_1000baseKX_Full (1 << 17)
#define SUPPORTED_10000baseKX4_Full (1 << 18)
#define SUPPORTED_10000baseKR_Full (1 << 19)
#define SUPPORTED_10000baseR_FEC (1 << 20)
#define SUPPORTED_20000baseMLD2_Full (1 << 21)
#define SUPPORTED_20000baseKR2_Full (1 << 22)
#define SUPPORTED_40000baseKR4_Full (1 << 23)
#define SUPPORTED_40000baseCR4_Full (1 << 24)
#define SUPPORTED_40000baseSR4_Full (1 << 25)
#define SUPPORTED_40000baseLR4_Full (1 << 26)
/* Indicates what features are advertised by the interface. */
#define ADVERTISED_10baseT_Half (1 << 0)
#define ADVERTISED_10baseT_Full (1 << 1)
#define ADVERTISED_100baseT_Half (1 << 2)
#define ADVERTISED_100baseT_Full (1 << 3)
#define ADVERTISED_1000baseT_Half (1 << 4)
#define ADVERTISED_1000baseT_Full (1 << 5)
#define ADVERTISED_Autoneg (1 << 6)
#define ADVERTISED_TP (1 << 7)
#define ADVERTISED_AUI (1 << 8)
#define ADVERTISED_MII (1 << 9)
#define ADVERTISED_FIBRE (1 << 10)
#define ADVERTISED_BNC (1 << 11)
#define ADVERTISED_10000baseT_Full (1 << 12)
#define ADVERTISED_Pause (1 << 13)
#define ADVERTISED_Asym_Pause (1 << 14)
#define ADVERTISED_2500baseX_Full (1 << 15)
#define ADVERTISED_Backplane (1 << 16)
#define ADVERTISED_1000baseKX_Full (1 << 17)
#define ADVERTISED_10000baseKX4_Full (1 << 18)
#define ADVERTISED_10000baseKR_Full (1 << 19)
#define ADVERTISED_10000baseR_FEC (1 << 20)
#define ADVERTISED_20000baseMLD2_Full (1 << 21)
#define ADVERTISED_20000baseKR2_Full (1 << 22)
#define ADVERTISED_40000baseKR4_Full (1 << 23)
#define ADVERTISED_40000baseCR4_Full (1 << 24)
#define ADVERTISED_40000baseSR4_Full (1 << 25)
#define ADVERTISED_40000baseLR4_Full (1 << 26)
/* The following are all involved in forcing a particular link mode for the
* device for setting things. When getting the devices settings, these
* indicate the current mode and whether it was forced up into this mode or
* autonegotiated.
*/
/* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */
#define SPEED_10 10
#define SPEED_100 100
#define SPEED_1000 1000
#define SPEED_2500 2500
#define SPEED_10000 10000
#define SPEED_UNKNOWN -1
/* Duplex, half or full. */
#define DUPLEX_HALF 0x00
#define DUPLEX_FULL 0x01
#define DUPLEX_UNKNOWN 0xff
/* Which connector port. */
#define PORT_TP 0x00
#define PORT_AUI 0x01
#define PORT_MII 0x02
#define PORT_FIBRE 0x03
#define PORT_BNC 0x04
#define PORT_DA 0x05
#define PORT_NONE 0xEF
#define PORT_OTHER 0xFF
/* Which transceiver to use. */
#define XCVR_INTERNAL 0x00
#define XCVR_EXTERNAL 0x01
#define XCVR_DUMMY1 0x02
#define XCVR_DUMMY2 0x03
#define XCVR_DUMMY3 0x04
/* Enable or disable autonegotiation. If this is set to enable, the forced
* link modes above are completely ignored.
*/
#define AUTONEG_DISABLE 0x00
#define AUTONEG_ENABLE 0x01
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif //__ETHTOOL_H__
/*************************** (C) COPYRIGHT 2018 HUGE-IC ***** END OF FILE *****/

View File

@@ -0,0 +1,205 @@
/**
******************************************************************************
* @file sdk/include/lib/ethernet_phy/mii.h
* @author HUGE-IC Application Team
* @version V1.0.0
* @date 10-10-2018
* @brief definitions for MII-compatible transceivers
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2018 HUGE-IC</center></h2>
*
*
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MII_H__
#define __MII_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @weakgroup NETWORK
* @{
*/
/** @defgroup NETWORK_MII MII Register
* @brief definitions for MII-compatible transceivers
* @{
*/
/** @defgroup MII_Exported_Constants Exported Constants
* @{
*/
/* Generic MII registers. */
#define MII_BMCR 0x00 /*!< Basic mode control register */
#define MII_BMSR 0x01 /*!< Basic mode status register */
#define MII_PHYSID1 0x02 /*!< PHYS ID 1 */
#define MII_PHYSID2 0x03 /*!< PHYS ID 2 */
#define MII_ADVERTISE 0x04 /*!< Advertisement control reg */
#define MII_LPA 0x05 /*!< Link partner ability reg */
#define MII_EXPANSION 0x06 /*!< Expansion register */
#define MII_CTRL1000 0x09 /*!< 1000BASE-T control */
#define MII_STAT1000 0x0a /*!< 1000BASE-T status */
#define MII_MMD_CTRL 0x0d /*!< MMD Access Control Register */
#define MII_MMD_DATA 0x0e /*!< MMD Access Data Register */
#define MII_ESTATUS 0x0f /*!< Extended Status */
#define MII_DCOUNTER 0x12 /*!< Disconnect counter */
#define MII_FCSCOUNTER 0x13 /*!< False carrier counter */
#define MII_NWAYTEST 0x14 /*!< N-way auto-neg test reg */
#define MII_RERRCOUNTER 0x15 /*!< Receive error counter */
#define MII_SREVISION 0x16 /*!< Silicon revision */
#define MII_RESV1 0x17 /*!< Reserved... */
#define MII_LBRERROR 0x18 /*!< Lpback, rx, bypass error */
#define MII_PHYADDR 0x19 /*!< PHY address */
#define MII_RESV2 0x1a /*!< Reserved... */
#define MII_TPISTATUS 0x1b /*!< TPI status for 10mbps */
#define MII_NCONFIG 0x1c /*!< Network interface config */
/* Basic mode control register. */
#define BMCR_RESV 0x003f /*!< Unused... */
#define BMCR_SPEED1000 0x0040 /*!< MSB of Speed (1000) */
#define BMCR_CTST 0x0080 /*!< Collision test */
#define BMCR_FULLDPLX 0x0100 /*!< Full duplex */
#define BMCR_ANRESTART 0x0200 /*!< Auto negotiation restart */
#define BMCR_ISOLATE 0x0400 /*!< Isolate data paths from MII */
#define BMCR_PDOWN 0x0800 /*!< Enable low power state */
#define BMCR_ANENABLE 0x1000 /*!< Enable auto negotiation */
#define BMCR_SPEED100 0x2000 /*!< Select 100Mbps */
#define BMCR_LOOPBACK 0x4000 /*!< TXD loopback bits */
#define BMCR_RESET 0x8000 /*!< Reset to default state */
/* Basic mode status register. */
#define BMSR_ERCAP 0x0001 /*!< Ext-reg capability */
#define BMSR_JCD 0x0002 /*!< Jabber detected */
#define BMSR_LSTATUS 0x0004 /*!< Link status */
#define BMSR_ANEGCAPABLE 0x0008 /*!< Able to do auto-negotiation */
#define BMSR_RFAULT 0x0010 /*!< Remote fault detected */
#define BMSR_ANEGCOMPLETE 0x0020 /*!< Auto-negotiation complete */
#define BMSR_RESV 0x00c0 /*!< Unused... */
#define BMSR_ESTATEN 0x0100 /*!< Extended Status in R15 */
#define BMSR_100HALF2 0x0200 /*!< Can do 100BASE-T2 HDX */
#define BMSR_100FULL2 0x0400 /*!< Can do 100BASE-T2 FDX */
#define BMSR_10HALF 0x0800 /*!< Can do 10mbps, half-duplex */
#define BMSR_10FULL 0x1000 /*!< Can do 10mbps, full-duplex */
#define BMSR_100HALF 0x2000 /*!< Can do 100mbps, half-duplex */
#define BMSR_100FULL 0x4000 /*!< Can do 100mbps, full-duplex */
#define BMSR_100BASE4 0x8000 /*!< Can do 100mbps, 4k packets */
/* Advertisement control register. */
#define ADVERTISE_SLCT 0x001f /*!< Selector bits */
#define ADVERTISE_CSMA 0x0001 /*!< Only selector supported */
#define ADVERTISE_10HALF 0x0020 /*!< Try for 10mbps half-duplex */
#define ADVERTISE_1000XFULL 0x0020 /*!< Try for 1000BASE-X full-duplex */
#define ADVERTISE_10FULL 0x0040 /*!< Try for 10mbps full-duplex */
#define ADVERTISE_1000XHALF 0x0040 /*!< Try for 1000BASE-X half-duplex */
#define ADVERTISE_100HALF 0x0080 /*!< Try for 100mbps half-duplex */
#define ADVERTISE_1000XPAUSE 0x0080 /*!< Try for 1000BASE-X pause */
#define ADVERTISE_100FULL 0x0100 /*!< Try for 100mbps full-duplex */
#define ADVERTISE_1000XPSE_ASYM 0x0100 /*!< Try for 1000BASE-X asym pause */
#define ADVERTISE_100BASE4 0x0200 /*!< Try for 100mbps 4k packets */
#define ADVERTISE_PAUSE_CAP 0x0400 /*!< Try for pause */
#define ADVERTISE_PAUSE_ASYM 0x0800 /*!< Try for asymetric pause */
#define ADVERTISE_RESV 0x1000 /*!< Unused... */
#define ADVERTISE_RFAULT 0x2000 /*!< Say we can detect faults */
#define ADVERTISE_LPACK 0x4000 /*!< Ack link partners response */
#define ADVERTISE_NPAGE 0x8000 /*!< Next page bit */
#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
ADVERTISE_CSMA)
#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
ADVERTISE_100HALF | ADVERTISE_100FULL)
/* Link partner ability register. */
#define LPA_SLCT 0x001f /*!< Same as advertise selector */
#define LPA_10HALF 0x0020 /*!< Can do 10mbps half-duplex */
#define LPA_1000XFULL 0x0020 /*!< Can do 1000BASE-X full-duplex */
#define LPA_10FULL 0x0040 /*!< Can do 10mbps full-duplex */
#define LPA_1000XHALF 0x0040 /*!< Can do 1000BASE-X half-duplex */
#define LPA_100HALF 0x0080 /*!< Can do 100mbps half-duplex */
#define LPA_1000XPAUSE 0x0080 /*!< Can do 1000BASE-X pause */
#define LPA_100FULL 0x0100 /*!< Can do 100mbps full-duplex */
#define LPA_1000XPAUSE_ASYM 0x0100 /*!< Can do 1000BASE-X pause asym */
#define LPA_100BASE4 0x0200 /*!< Can do 100mbps 4k packets */
#define LPA_PAUSE_CAP 0x0400 /*!< Can pause */
#define LPA_PAUSE_ASYM 0x0800 /*!< Can pause asymetrically */
#define LPA_RESV 0x1000 /*!< Unused... */
#define LPA_RFAULT 0x2000 /*!< Link partner faulted */
#define LPA_LPACK 0x4000 /*!< Link partner acked us */
#define LPA_NPAGE 0x8000 /*!< Next page bit */
#define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
#define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
/* Expansion register for auto-negotiation. */
#define EXPANSION_NWAY 0x0001 /*!< Can do N-way auto-nego */
#define EXPANSION_LCWP 0x0002 /*!< Got new RX page code word */
#define EXPANSION_ENABLENPAGE 0x0004 /*!< This enables npage words */
#define EXPANSION_NPCAPABLE 0x0008 /*!< Link partner supports npage */
#define EXPANSION_MFAULTS 0x0010 /*!< Multiple faults detected */
#define EXPANSION_RESV 0xffe0 /*!< Unused... */
#define ESTATUS_1000_TFULL 0x2000 /*!< Can do 1000BT Full */
#define ESTATUS_1000_THALF 0x1000 /*!< Can do 1000BT Half */
/* N-way test register. */
#define NWAYTEST_RESV1 0x00ff /*!< Unused... */
#define NWAYTEST_LOOPBACK 0x0100 /*!< Enable loopback for N-way */
#define NWAYTEST_RESV2 0xfe00 /*!< Unused... */
/* 1000BASE-T Control register */
#define ADVERTISE_1000FULL 0x0200 /*!< Advertise 1000BASE-T full duplex */
#define ADVERTISE_1000HALF 0x0100 /*!< Advertise 1000BASE-T half duplex */
#define CTL1000_AS_MASTER 0x0800
#define CTL1000_ENABLE_MASTER 0x1000
/* 1000BASE-T Status register */
#define LPA_1000LOCALRXOK 0x2000 /*!< Link partner local receiver status */
#define LPA_1000REMRXOK 0x1000 /*!< Link partner remote receiver status*/
#define LPA_1000FULL 0x0800 /*!< Link partner 1000BASE-T full duplex*/
#define LPA_1000HALF 0x0400 /*!< Link partner 1000BASE-T half duplex*/
/* Flow control flags */
#define FLOW_CTRL_TX 0x01
#define FLOW_CTRL_RX 0x02
/* MMD Access Control register fields */
#define MII_MMD_CTRL_DEVAD_MASK 0x1f /*!< Mask MMD DEVAD */
#define MII_MMD_CTRL_ADDR 0x0000 /*!< Address */
#define MII_MMD_CTRL_NOINCR 0x4000 /*!< no post increment */
#define MII_MMD_CTRL_INCR_RDWT 0x8000 /*!< post increment on reads & writes */
#define MII_MMD_CTRL_INCR_ON_WT 0xC000 /*!< post increment on writes only */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif //__MII_H__
/*************************** (C) COPYRIGHT 2018 HUGE-IC ***** END OF FILE *****/

View File

@@ -0,0 +1,7 @@
#ifndef __AUTO_PHY_H_
#define __AUTO_PHY_H_
extern struct ethernet_phy_driver auto_phy_driver;
#endif

View File

@@ -0,0 +1,7 @@
#ifndef __IP101G_H_
#define __IP101G_H_
extern struct ethernet_phy_driver ip101g_driver;
#endif

View File

@@ -0,0 +1,7 @@
#ifndef __RTL8201F_H_
#define __RTL8201F_H_
extern struct ethernet_phy_driver rtl8201f_driver;
#endif

View File

@@ -0,0 +1,7 @@
#ifndef __SZ18201_H_
#define __SZ18201_H_
extern struct ethernet_phy_driver sz18201_driver;
#endif

View File

@@ -0,0 +1,26 @@
#ifndef _SDK_SKMONITOR_H_
#define _SDK_SKMONITOR_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
SOCK_MONITOR_READ = BIT(0),
SOCK_MONITOR_WRITE = BIT(1),
SOCK_MONITOR_ERROR = BIT(2),
} skmonitor_flags;
typedef void (*skmonitor_cb)(uint16 sock, skmonitor_flags flags, uint32 priv);
int32 sock_monitor_init(void);
void sock_monitor_dump(void);
/* 注册到skmonitor的socket不能再由模块task自己主动读取只能由skmonitor触发执行读取 */
int32 sock_monitor_add(uint16 sock, skmonitor_flags flags, skmonitor_cb cb, uint32 priv);
void sock_monitor_del(uint16 sock);
void sock_monitor_disable(uint16 sock, uint8 disable);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,86 @@
#ifndef __SSL_SOCKET_ADAPTER_H__
#define __SSL_SOCKET_ADAPTER_H__
typedef struct {
int8 is_server;
int8 verify_cert; // 是否验证客户端证书0=不验证1=验证)
int8 debug, r2;
const char *cert; // 服务器证书数据PEM/DER 自动识别)
const char *key; // 服务器私钥数据PEM/DER 自动识别)
const char *ca_cert; // CA证书数据仅verify_cert=1时需传
uint32 max_session_cache; // 会话缓存最大条目默认100
uint32 session_timeout_sec; // 会话超时时间默认30
} ssl_sock_init_param;
typedef struct {
/**
* @brief 初始化SSL全局上下文
* @param param 初始化参数
* @return void * 全局上下文指针
*/
void *(*global_init)(const ssl_sock_init_param *param);
/**
* @brief 全局资源销毁
* @param global_ctx 全局上下文指针
*/
void (*global_destroy)(void *global_ctx);
/**
* @brief 创建连接上下文
* @param global_ctx 全局上下文指针
* @return void * 连接上下文指针
*/
void *(*conn_create)(void *global_ctx);
/**
* @brief 连接上下文销毁
* @param conn_ctx 连接上下文指针
*/
void (*conn_destroy)(void *conn_ctx);
/**
* @brief TLS握手
* @param conn_ctx 连接上下文指针
* @param sockfd 套接字文件描述符
* @param step 是否由外部代码控制握手过程
* @return int 0成功-1失败
*/
int (*handshake)(void *conn_ctx, int sockfd, int step);
/**
* @brief 加密发送
* @param conn_ctx 连接上下文指针
* @param data 数据指针
* @param len 数据长度
* @return int32 发送字节数
*/
int32(*send)(void *conn_ctx, const uint8 *data, uint32 len);
/**
* @brief 加密接收
* @param conn_ctx 连接上下文指针
* @param buf 接收缓冲区指针
* @param buf_len 接收缓冲区长度
* @return int32 接收字节数
*/
int32(*recv)(void *conn_ctx, uint8 *buf, uint32 buf_len);
/**
* @brief 优雅关闭
* @param conn_ctx 连接上下文指针
*/
void (*shutdown)(void *conn_ctx);
/**
* @brief 获取错误信息
* @param conn_ctx 连接上下文指针
* @return const char* 错误信息指针
*/
const char *(*get_error)(void *conn_ctx);
} sslsock_ops;
extern const sslsock_ops sslsock_mbedtls_ops;
#endif // __UHTTPD_SSL_ADAPTER_H__

View File

@@ -0,0 +1,82 @@
#ifndef _TX_UHTTPD_H_
#define _TX_UHTTPD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "lib/net/sslsock/ssl_sock.h"
#define uhttpd_dbg(fmt, ...) //os_printf(KERN_ERR fmt, ##__VA_ARGS__)
#define uhttpd_err(fmt, ...) os_printf(KERN_ERR fmt, ##__VA_ARGS__)
#define UHTTPD_RXBUF_SIZE (1536)
enum UHTTPD_VALUE_TYPE {
UHTTPD_VALUE_TYPE_UINT32,
UHTTPD_VALUE_TYPE_UINT8,
UHTTPD_VALUE_TYPE_UINT16,
UHTTPD_VALUE_TYPE_STRING,
UHTTPD_VALUE_TYPE_UINT32_BIT,
UHTTPD_VALUE_TYPE_UINT8_BIT,
UHTTPD_VALUE_TYPE_UINT16_BIT,
UHTTPD_VALUE_TYPE_IPV4,
UHTTPD_VALUE_TYPE_MACV4,
UHTTPD_VALUE_TYPE_CMD,
UHTTPD_VALUE_TYPE_SARRAY,
UHTTPD_VALUE_TYPE_RET_INT8,
UHTTPD_VALUE_TYPE_RET_UINT8,
UHTTPD_VALUE_TYPE_RET_INT16,
UHTTPD_VALUE_TYPE_RET_UINT16,
UHTTPD_VALUE_TYPE_RET_INT32,
UHTTPD_VALUE_TYPE_RET_UINT32,
UHTTPD_VALUE_TYPE_RET_INT64,
UHTTPD_VALUE_TYPE_RET_UINT64,
UHTTPD_VALUE_TYPE_RET_STRING,
};
enum UHTTPD_VALUE_FLAGS {
UHTTPD_VALUE_FLAGS_READONLY = BIT(0),
};
typedef void(*uhttpd_val_cmdhdl)(int32 sock, char *val, char *resp, int32 size, uint32 *resp_len);
struct uhttpd_value_entry {
char *name;
void *value;
uint32 type: 5, maxlen: 8, bitoff: 5, maskbit: 5, flags: 2, rev: 7;
};
struct uhttpd_html {
const char *name;
const char *html;
uint32 size;
};
typedef void (*uhttpd_action_hdl)(int32 sock, uint32 client_ip, char *buff, uint32 size);
struct uhttpd_action {
char *name;
uhttpd_action_hdl hdl;
};
int32 uhttpd_start(char *ifname, uint32 port, const sslsock_ops *ssl, const ssl_sock_init_param *param);
void uhttpd_stop(void);
////////////////////////////////////////////////////////////////////////////
int32 uhttpd_send_resp(int32 sock, uint32 status, uint8 gzip, char *values, int vlen, uint32 flash);
int32 uhttpd_resp_status(int32 sock, char *resp, uint8 status);
void uhttpd_proc_post(int32 sock, uint32 client_ip, char *buf, uint32 len);
void uhttpd_proc_get(int32 sock, uint32 client_ip, char *buf, uint32 len);
int32 uhttpd_get_flash_data(uint32 addr, uint32 len, uint8 *buff);
const struct uhttpd_html *uhttpd_find_html(char *url);
const struct uhttpd_action *uhttpd_action_find(int32 sock, uint32 client_ip, char *buf, uint32 len);
const struct uhttpd_value_entry *uhttpd_find_value(char *name);
void uhttpd_proc_auth_action(int32 sock, uint32 client_ip, char *buf, uint32 len);
void uhttpd_proc_post_action(int32 sock, uint32 client_ip, char *buf, uint32 len);
void uhttpd_proc_options(int32 sock, uint32 client_ip, char *buff, uint32 len);
void uhttpd_proc_firmware_upg(int32 sock, uint32 client_ip, char *buf, uint32 size);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,476 @@
/**
* @file url_file.h
* @brief URL 文件流处理库头文件
*
* 该模块提供了一个统一的接口来处理基于不同协议(如 HTTP, RTSP, FILE 等)的 URL 资源。
* 它抽象了底层的网络套接字操作、数据缓冲、播放列表解析以及断点续传等功能,
* 使得上层应用可以像操作普通文件一样操作网络流。
*/
#ifndef _URL_FILE_H_
#define _URL_FILE_H_
#include "basic_include.h"
#include "lib/common/rbuffer.h"
#include "lib/posix/stdio.h"
#include "lwip/opt.h"
#include "lwip/sockets.h"
#include "lwip/inet_chksum.h"
#include "netif/etharp.h"
#include "netif/ethernetif.h"
#include "lwip/ip.h"
#include "lwip/init.h"
#include "lib/net/skmonitor/skmonitor.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
/** @brief 通用调试打印宏 */
#define UF_DEBUG(f,...) os_printf("%s:%d:"f, __FUNCTION__, __LINE__, ##__VA_ARGS__)
/** @brief 错误日志打印宏 (带内核错误前缀) */
#define UF_ERR(f,...) os_printf(KERN_ERR"%s:%d:"f, __FUNCTION__, __LINE__, ##__VA_ARGS__)
/** @brief 获取读锁 (阻塞直到获取成功) */
#define UF_LOCK_READ(uf) os_mutex_lock(&uf->r_lock, osWaitForever)
/** @brief 释放读锁 */
#define UF_UNLOCK_READ(uf) os_mutex_unlock(&uf->r_lock)
/** @brief 获取写锁 (阻塞直到获取成功) */
#define UF_LOCK_WRITE(uf) os_mutex_lock(&uf->w_lock, osWaitForever)
/** @brief 释放写锁 */
#define UF_UNLOCK_WRITE(uf) os_mutex_unlock(&uf->w_lock)
/** @brief 获取协议保护锁 (阻塞直到获取成功) */
#define UF_LOCK_PROTO(uf) os_mutex_lock(&uf->lock, osWaitForever)
/** @brief 释放协议保护锁 */
#define UF_UNLOCK_PROTO(uf) os_mutex_unlock(&uf->lock)
/** @brief 检查是否处于读模式 */
#define UF_READ(uf) ((uf)->mode & UF_MODE_RD)
/** @brief 检查是否处于写模式 */
#define UF_WRITE(uf) ((uf)->mode & UF_MODE_WR)
/** @brief 检查是否处于 AV (音视频) 模式 */
#define UF_AVMODE(uf) ((uf)->mode & UF_MODE_AV)
/**
* @brief URL 文件处理状态
*/
typedef enum {
UF_CLOSE = -2, /**< 需要关闭,此状态只能由 uf_close 设置 */
UF_ERROR = -1, /**< 发生错误 */
UF_NONE = 0, /**< 初始状态 */
UF_ROPEN = 1, /**< 重新打开中 */
UF_OPEN = 2, /**< 开始打开连接 */
UF_RUN = 3, /**< 数据传输中 */
UF_DONE = 4 /**< 数据传输完成,处于空闲状态 */
} UF_STATE;
/**
* @brief URL 文件操作模式位掩码
*/
typedef enum {
UF_MODE_AV = BIT(0), /**< AV 模式 (音视频流) */
UF_MODE_RD = BIT(1), /**< 支持读取 */
UF_MODE_WR = BIT(2), /**< 支持写入 */
UF_MODE_RECV = BIT(3), /**< 客户自定义接收模式 (通过回调获取数据) */
UF_MODE_MONITOR = BIT(4), /**< 使用 Socket 监控模式 (不创建独立任务) */
UF_MODE_AUTO_RUN = BIT(5), /**< 自动运行模式 (打开后立即启动传输) */
} UF_MODE;
/**
* @brief 支持的播放列表格式类型
*/
typedef enum {
UF_PLAYLIST_NONE = 0, /**< 无播放列表 */
UF_PLAYLIST_CUST, /**< 自定义格式 */
UF_PLAYLIST_HLS, /**< HLS (.m3u8) */
UF_PLAYLIST_ASX, /**< ASX (Windows Media) */
UF_PLAYLIST_MMSREF, /**< MMS Reference */
UF_PLAYLIST_M3U, /**< M3U */
UF_PLAYLIST_PLS, /**< PLS */
UF_PLAYLIST_NSC, /**< NSC (Netshow) */
UF_PLAYLIST_SMIL, /**< SMIL */
UF_PLAYLIST_XSPF, /**< XSPF */
UF_PLAYLIST_MAX, /**< 类型总数 */
} UF_PLAYLIST_TYPE;
/**
* @brief IO 控制命令
*/
typedef enum {
UF_IOCTL_CMD_IDLE, /**< 空闲命令 */
UF_IOCTL_CMD_SOCK_ERROR, /**< 获取/设置 Socket 错误 */
UF_IOCTL_CMD_GET_FILESIZE, /**< 获取文件大小 */
UF_IOCTL_CMD_GET_TOTALTIME, /**< 获取总时长 (媒体文件) */
UF_IOCTL_CMD_SET_EVTCB, /**< 设置事件回调函数 */
UF_IOCTL_CMD_SET_BREAKPOINT_CONTINUALLY,/**< 设置断点续传参数 */
UF_IOCTL_CMD_SET_HTTP_HEADER, /**< 设置自定义 HTTP 头 */
UF_IOCTL_CMD_SET_HTTP_UPSIZE, /**< 设置 HTTP 上传大小 */
} UF_IOCTL_CMD;
/**
* @brief URL 文件事件类型
*/
typedef enum {
UF_EVENT_RECVD_DATA, /**< 接收到数据事件 (用于 UF_MODE_RECV 模式) */
UF_EVENT_TRANS_COMPLETE, /**< 传输完成事件 */
} UF_EVENT;
struct urlfile;
/**
* @brief 协议层操作函数集
*
* 每个支持的协议 (如 http, rtsp, file) 都需要实现此结构体中的函数指针。
*/
struct ufprotocol_ops {
/** @brief 初始化协议上下文 */
int (*do_init)(struct urlfile *file);
/** @brief 释放协议资源 */
int (*do_release)(struct urlfile *file);
/** @brief 执行主传输循环 */
int (*do_run)(struct urlfile *file);
/** @brief seek 操作 (跳转) */
int (*do_seek)(struct urlfile *file, long offset, int whence);
/** @brief 发送数据 */
int (*do_send)(struct urlfile *file, void *data, size_t size);
/** @brief 协议特定的 IO 控制 */
int (*do_ioctl)(struct urlfile *file, uint32 cmd, uint32 param1, uint32 param2);
};
/**
* @brief 协议描述符
*/
struct ufprotocol {
const char *name; /**< 协议名称 (如 "http", "rtsp") */
const struct ufprotocol_ops *ops; /**< 操作函数集指针 */
};
/**
* @brief 事件回调函数类型
*
* @param file URL 文件句柄
* @param evet 事件类型 (@ref UF_EVENT)
* @param param1 参数 1 (取决于事件类型)
* @param param2 参数 2 (取决于事件类型)
* @return int32 处理结果
*/
typedef int32(*uf_evt_cb)(struct urlfile *file, uint32 evet, uint32 param1, uint32 param2);
/**
* @brief 播放列表条目
*/
struct uf_playlist_entry {
struct list_head list; /**< 链表节点 */
char *title; /**< 媒体标题 */
char *url; /**< 媒体 URL */
};
/**
* @brief 播放列表容器
*/
struct uf_playlist {
uint8 *buff_addr; /**< 缓冲区地址 (用于存储原始播放列表数据) */
uint32 buff_size; /**< 缓冲区总大小 */
uint32 buff_len; /**< 当前已填充长度 */
int16 type; /**< 播放列表类型 (@ref UF_PLAYLIST_TYPE) */
uint16 count; /**< 条目数量 */
struct list_head list;/**< 条目链表头 */
};
/**
* @brief URL 文件核心控制结构
*
* 该结构体维护了一个 URL 资源的所有状态,包括网络连接、缓冲、状态机、播放列表等。
*/
struct urlfile {
uint8 mode; /**< 打开模式: 0:AVMODE, BIT0:read; BIT1:write; others:customize */
int8 state; /**< URL 文件当前状态 (@ref UF_STATE) */
uint16 sock; /**< 关联的 Socket 描述符 */
char *url; /**< 当前打开的 URL 字符串 */
off_t size; /**< 文件总大小。初始为 0连接成功后设置。若未知 (如直播流) 则设为 -1 */
off_t cur_pos; /**< 当前读取位置 */
off_t doffset; /**< 当前下载偏移量 (用于断点续传) */
void *priv; /**< 协议层私有数据指针 */
uf_evt_cb evt_cb; /**< 事件回调函数指针 */
struct os_mutex lock; /**< 全局互斥锁 (保护主要状态) */
struct os_mutex r_lock; /**< 读操作互斥锁 */
struct os_mutex w_lock; /**< 写操作互斥锁 */
uint64 open_tick; /**< 打开时的系统 tick 计数 ,用于统计网络打开延时 */
const struct ufprotocol *proto; /**< 匹配的协议描述符指针 */
struct rbuffer buffer; /**< 接收数据环形缓冲区 */
void *task; /**< 处理任务句柄 (若非监控模式) */
struct uf_playlist playlist; /**< 播放列表信息 */
uint16 playindex; /**< 当前播放的索引 */
uint8 seek_type; /**< Seek 类型标志 */
uint8 rev; /**< 保留字段 */
};
/* ================= 外部API声明 ================= */
/**
* @brief 打开 URL 资源
*
* 根据 URL 协议类型创建相应的处理实例,并初始化资源。
*
* @param url 资源 URL 字符串 (如 "http://...", "rtsp://...")
* @param mode 模式字符串:
* - 'v': AV 模式 (音视频流)
* - 'r': 支持读取
* - 'w': 支持写入
* - 'c': 客户自定义接收模式 (不需要调用 uf_read数据通过 UF_EVENT_RECVD_DATA 回调输出,需配合 UF_IOCTL_CMD_SET_EVTCB)
* - 'm': 使用 Socket 监控模式 (不为此 urlfile 创建独立任务)
* - 'a': 自动运行模式 (打开后自动开始传输)
* @param flags 额外标志位
* @return void* 成功返回 urlfile 句柄,失败返回 NULL
*/
void *uf_open(char *url, char *mode, uint32 flags);
/**
* @brief 关闭 URL 资源
*
* 释放所有关联资源,断开连接,停止任务。
*
* @param file urlfile 句柄
*/
void uf_close(void *file);
/**
* @brief 从 URL 资源读取数据
*
* 类似于标准 fread从内部缓冲区拷贝数据到用户缓冲区。
*
* @param ptr 用户缓冲区指针
* @param size 单个元素大小
* @param nmemb 元素个数
* @param file urlfile 句柄
* @return size_t 实际读取的元素个数
*/
size_t uf_read(void *ptr, size_t size, size_t nmemb, void *file);
/**
* @brief 向 URL 资源写入数据
*
* 类似于标准 fwrite将用户数据发送到远程端。
*
* @param ptr 用户数据指针
* @param size 单个元素大小
* @param nmemb 元素个数
* @param file urlfile 句柄
* @return size_t 实际写入的元素个数
*/
size_t uf_write(void *ptr, size_t size, size_t nmemb, void *file);
/**
* @brief 移动读写指针
*
* @param file urlfile 句柄
* @param offset 偏移量
* @param whence 起始位置 (SEEK_SET, SEEK_CUR, SEEK_END)
* @return int 0: 成功; -1: 失败
*/
int uf_seek(void *file, long offset, int whence);
/**
* @brief 获取当前读写指针位置
*
* @param file urlfile 句柄
* @return off_t 当前位置
*/
off_t uf_tell(void *file);
/**
* @brief 检查是否到达文件末尾
*
* @param file urlfile 句柄
* @return int 1: 到达末尾; 0: 未到达
*/
int uf_eof(void *file);
/**
* @brief IO 控制接口
*
* 用于设置或获取特定参数 (如回调、HTTP 头、文件大小等)。
*
* @param file urlfile 句柄
* @param cmd 控制命令 (@ref UF_IOCTL_CMD)
* @param param1 参数 1
* @param param2 参数 2
* @return int 操作结果
*/
int uf_ioctl(void *file, uint32 cmd, uint32 param1, uint32 param2);
/**
* @brief 获取文件大小
*
* 尝试获取远程文件的总大小。如果当前接收的数据量不足以判断大小,可能返回 0。
*
* @param fp urlfile 句柄
* @param size 触发检查的最小数据阈值
* @return off_t 文件总大小;若未知或条件不满足返回 0
*/
off_t uf_filesize(void *fp, uint32 size);
/**
* @brief 获取 Seek 类型
*
* @param fp urlfile 句柄
* @return int32 Seek 类型标识
*/
int32 uf_seektype(void *fp);
/**
* @brief 获取有效数据大小及缓冲水位
*
* @param fp urlfile 句柄
* @param buffer_level 输出参数:当前缓冲区水位 (百分比)
* @return off_t 有效数据总大小
*/
off_t uf_datasize(void *fp, uint8 *buffer_level);
/**
* @brief 分配内存 -- 具体实现在 app_mem.c
* @param size 请求大小
* @return void* 内存指针
*/
void *uf_alloc(int32 size);
/**
* @brief 释放内存 -- 具体实现在 app_mem.c
* @param ptr 内存指针
*/
void uf_free(void *ptr);
/**
* @brief 复制字符串
* @param s 源字符串
* @return char* 新分配的字符串副本
*/
char *uf_strdup(char *s);
/**
* @brief urlfile状态切换内部使用
* @param file urlfile 句柄
* @param state 新状态
*/
void uf_state(struct urlfile *file, UF_STATE state);
/**
* @brief 初始化 URL 文件系统
*
* 注册支持的协议列表。
*
* @param protos 协议描述符数组
* @param count 数组元素个数
*/
void urlfile_init(const struct ufprotocol *protos, int count);
/* ================= 协议内部使用的API ================= */
/**
* @brief 将数据存入内部缓冲区
*
* @param file urlfile 句柄
* @param data 数据指针
* @param len 数据长度
* @return size_t 实际存入的长度
*/
size_t uf_store_data(struct urlfile *file, char *data, size_t len);
/**
* @brief 解析播放列表数据
*
* @param list 播放列表结构
* @param data 原始数据
* @param len 数据长度
* @param tot_size 总大小
* @return int 解析到的条目数
*/
int uf_playlist_recieve(struct uf_playlist *list, char *data, int len, uint32 tot_size);
/**
* @brief 检测播放列表类型
*
* @param list 播放列表结构
* @param data 数据样本
* @param size 样本大小
*/
void uf_playlist_detect(struct uf_playlist *list, void *data, size_t size);
/**
* @brief 构建播放列表
*
* @param list 播放列表结构
* @param urls 包含 URL 的字符串
* @return int32 0: 成功; 负值: 失败
*/
int32 uf_playlist_build(struct uf_playlist *list, char *urls);
/**
* @brief 释放播放列表资源
*
* @param list 播放列表结构
* @return int32 0: 成功
*/
int32 uf_playlist_free(struct uf_playlist *list);
/**
* @brief 向播放列表添加新 URL
*
* @param list 播放列表结构
* @param title 标题
* @param url URL 字符串
* @return int32 0: 成功; 负值: 失败
*/
int32 uf_playlist_new_url(struct uf_playlist *list, char *title, char *url);
/**
* @brief 获取播放列表中指定索引的 URL
*
* @param list 播放列表结构
* @param index 索引
* @return char* URL 字符串
*/
char *uf_playlist_get_url(struct uf_playlist *list, uint16 index);
/**
* @brief 从缓冲区获取下一行文本
*
* @param buf 缓冲区
* @param line 输出:行起始指针
* @return char* 下一行的起始位置或 NULL
*/
char *uf_playlist_get_line(char *buf, char **line);
/**
* @brief 根据 URL 查找匹配的协议处理者
*
* @param url URL 字符串
* @return const struct ufprotocol* 匹配的协议描述符,未找到返回 NULL
*/
const struct ufprotocol *uf_findproto(char *url);
/* ================= 外部声明 ================= */
/** @brief 外部声明CURL HTTP 协议操作集 */
extern const struct ufprotocol_ops uf_curl_http;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,95 @@
#ifndef _HGSDK_NETUTILS_H_
#define _HGSDK_NETUTILS_H_
#include "dev.h"
#include "hal/netdev.h"
#ifdef __cplusplus
extern "C" {
#endif
struct udpdata_info {
uint8 *dest, *src;
uint32 dest_ip, dest_port;
uint32 src_ip, src_port;
uint8 *data;
uint32 len;
};
struct icmp_info {
uint8 *dest, *src;
uint32 dest_ip;
uint32 src_ip;
uint8 *data;
uint32 len;
uint8 type;
uint16 sn;
};
uint16 net_checksum(uint16 initcksum, uint8 *data, int32 len);
uint16 net_pseudo_checksum(uint8 proto, uint8 *data, uint16 len, uint32 *srcaddr, uint32 *destaddr);
uint16 net6_pseudo_checksum(uint8 *srcip, uint8 *destip, uint16 nexthdr, uint8 *payload, uint16 plen);
uint16 net_setup_udpdata(struct udpdata_info *data, uint8 *udp);
int32 net_setup_icmp(struct icmp_info *data, uint8 *icmp);
void wnb_ota_init(void);
void net_atcmd_init(void);
void netlog_init(uint16 port);
int32 sntp_client_init(char *ntp_server, uint16 update_interval);
void sntp_client_fresh(void);
void sntp_set_server(char *ntp_server);
void sntp_set_interval(uint16 interval);
void sntp_client_disable(int8 disable);
void sntp_set_sport(uint16 server_port);
int32 dns_redirect_init(void);
int32 dns_redirect_add(const char *domain, const char *ifname);
void icmp_pkt_monitor(const char *prefix, uint8 *data, uint32 len);
void icmp_pkt_monitor_scatter(const char *prefix, scatter_data *data, uint32 count);
int32 icmp_monitor_init(void);
uint32 net_get_dhcp_transID(uint8 *ether_data, uint8 **client_mac);
uint8 net_get_dhcp_msgtype(uint8 *opt, uint32 len);
uint8 net_get_dhcpv6_msgtype(uint8 *opt, uint32 len);
uint8 *net_get_dhcp_option(uint8 *opt, uint32 len, uint8 opcode, uint32 *olen);
const char *dhcpv6_msgtype_str(uint8 type);
const char *dhcp_msgtype_str(uint8 type);
int32 wifi_mcastfw_enable(uint8 enable, uint8 TOTAL_1s, uint8 EACH_1s, uint8 dhcp_only);
void wifi_mcastfw_clear(void);
void auto_wds_init(void);
void auto_wds_update(uint8 ifidx, uint32 valid_ip);
static inline int32 ipv4_is_mcast_addr(uint32 ip)
{
return (ip > 0xE0000000 && ip <= 0xEFFFFFFF) || (ip&0xff) == 0xff;
}
static inline int32 ipv6_is_mcast_addr(uint8 *ip)
{
return ip[0] == 0xff;
}
typedef enum {
SSWITCH_RULE_CHECK_PORT_INPUT,
SSWITCH_RULE_CHECK_LOCAL_INPUT,
SSWITCH_RULE_CHECK_FORWARD,
SSWITCH_RULE_CHECK_LOCAL_OUTPUT,
SSWITCH_RULE_CHECK_LOCAL_OUTPUT_SCATTER,
} SSWITCH_RULE_CHECK;
typedef enum {
SSWITCH_FLAGS_STATIC_ONLY = BIT(0), // Only use static MAC tables, do not dynamically update MAC tables
SSWITCH_FLAGS_FORWARD_UCAST = BIT(1), // Allow forwarding of unicast packets with unknown destinations
SSWITCH_FLAGS_FORWARD_MCAST = BIT(2), // Allow forwarding of multicast packets
} SSWITCH_FLAGS;
void sswitch_dev_status(void);
void sswitch_dev_mactbl_dump(void);
void sswitch_dev_mactbl_delete(uint8 *addr);
void sswitch_dev_mactbl_update(uint8 sport, uint8 *src_mac, uint8 is_static);
int32 sswitch_dev_port_enable(uint8 port_id, uint8 enable);
int32 sswitch_dev_port_config(uint8 port_id, struct netdev *ndev, uint8 mac);
int32 sswitch_dev_rule_check(SSWITCH_RULE_CHECK type, uint8 *data, uint32 len, uint32 port);
int32 sswitch_init(uint8 port_cnt, uint32 mactbl_max, SSWITCH_FLAGS flags);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,19 @@
#ifndef _WIFI_ZROAM_H_
#define _WIFI_ZROAM_H_
#include "lib/skb/skb.h"
#include "lib/bus/macbus/mac_bus.h"
#include "lib/skb/skb_list.h"
#include "lib/lmac/lmac_def.h"
#include "lib/lmac/hgic.h"
struct wifi_zroam_config {
uint16 MDID;
uint8 zroam_psk[32];
};
struct lmac_ops *wifi_zroam_init(uint8 master, struct lmac_ops *lops, uint32 bus_type, struct wifi_zroam_config *cfg);
void wifi_zroam_start(uint8 start);
int32 wifi_zroam_recv(uint8 *data, uint32 len);
#endif