add netif, dhcp, netbios, mDSN names

This commit is contained in:
pvvx 2017-03-11 06:10:30 +03:00
parent 255332ad03
commit 30329bd439
18 changed files with 2352 additions and 2319 deletions

View file

@ -16,7 +16,7 @@
#include <wifi/wifi_conf.h> #include <wifi/wifi_conf.h>
#include <wifi/wifi_util.h> #include <wifi/wifi_util.h>
rtw_mode_t wifi_mode = RTW_MODE_STA; extern rtw_mode_t wifi_mode; // = RTW_MODE_STA;
#endif #endif

View file

@ -481,6 +481,12 @@ struct pbuf *udp_packet_buffer, struct ip_addr *sender_addr, uint16_t sender_por
pbuf_free(udp_packet_buffer); pbuf_free(udp_packet_buffer);
} }
void dhcps_set_addr_pool(int addr_pool_set, struct ip_addr * addr_pool_start, struct ip_addr *addr_pool_end)
{
dhcps_ip4addr_pool_start = ip4_addr4(addr_pool_start);
dhcps_ip4addr_pool_end = ip4_addr4(addr_pool_end);
}
/** /**
* @brief Initialize dhcp server. * @brief Initialize dhcp server.
* @param None. * @param None.

View file

@ -89,6 +89,13 @@
static void arp_timer(void *arg); static void arp_timer(void *arg);
#if LWIP_NETIF_HOSTNAME
char lwip_host_name[NET_IF_NUM][LWIP_NETIF_HOSTNAME_SIZE] = {
DEF_HOSTNAME"0",
DEF_HOSTNAME"1",
DEF_HOSTNAME"2"
};
#endif
/** /**
* In this function, the hardware should be initialized. * In this function, the hardware should be initialized.
@ -132,8 +139,6 @@ static void low_level_init(struct netif *netif)
static err_t low_level_output(struct netif *netif, struct pbuf *p) static err_t low_level_output(struct netif *netif, struct pbuf *p)
{ {
/* Refer to eCos lwip eth_drv_send() */ /* Refer to eCos lwip eth_drv_send() */
struct eth_drv_sg sg_list[MAX_ETH_DRV_SG]; struct eth_drv_sg sg_list[MAX_ETH_DRV_SG];
int sg_len = 0; int sg_len = 0;
@ -294,9 +299,9 @@ err_t ethernetif_init(struct netif *netif)
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */ /* Initialize interface hostname */
if(netif->name[1] == '0') if(netif->name[1] == '0')
netif->hostname = "lwip0"; netif->hostname = lwip_host_name[0];
else if(netif->name[1] == '1') else if(netif->name[1] == '1')
netif->hostname = "lwip1"; netif->hostname = lwip_host_name[1];
#endif /* LWIP_NETIF_HOSTNAME */ #endif /* LWIP_NETIF_HOSTNAME */
netif->output = etharp_output; netif->output = etharp_output;
@ -312,13 +317,14 @@ err_t ethernetif_init(struct netif *netif)
return ERR_OK; return ERR_OK;
} }
#if CONFIG_ETHERNET #if CONFIG_ETHERNET
err_t ethernetif_mii_init(struct netif *netif) err_t ethernetif_mii_init(struct netif *netif)
{ {
LWIP_ASSERT("netif != NULL", (netif != NULL)); LWIP_ASSERT("netif != NULL", (netif != NULL));
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
netif->hostname = "lwip2"; netif->hostname = lwip_host_name[2];
#endif /* LWIP_NETIF_HOSTNAME */ #endif /* LWIP_NETIF_HOSTNAME */
netif->output = etharp_output; netif->output = etharp_output;
@ -335,6 +341,7 @@ err_t ethernetif_mii_init(struct netif *netif)
return ERR_OK; return ERR_OK;
} }
#endif #endif
static void arp_timer(void *arg) static void arp_timer(void *arg)
{ {
etharp_tmr(); etharp_tmr();

View file

@ -2,9 +2,17 @@
#define __ETHERNETIF_H__ #define __ETHERNETIF_H__
#include "autoconf.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#if LWIP_NETIF_HOSTNAME
#ifndef LWIP_NETIF_HOSTNAME_SIZE
#define LWIP_NETIF_HOSTNAME_SIZE 16
#endif
extern char lwip_host_name[NET_IF_NUM][LWIP_NETIF_HOSTNAME_SIZE];
#endif
//----- ------------------------------------------------------------------ //----- ------------------------------------------------------------------
// Ethernet Buffer // Ethernet Buffer
//----- ------------------------------------------------------------------ //----- ------------------------------------------------------------------

View file

@ -25,12 +25,12 @@ uint32_t mDNSPlatformInetAddr(char *cp)
// Mandatory function to get hostname // Mandatory function to get hostname
// called when mDNS initialization // called when mDNS initialization
char *mDNSPlatformHostname(void) _WEAK char *mDNSPlatformHostname(void)
{ {
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
return xnetif[0].hostname; return xnetif[0].hostname;
#else #else
return "ameba"; return DEF_HOSTNAME;
#endif #endif
} }

View file

@ -36,7 +36,7 @@
#include "rtl8195a/rtl_common.h" #include "rtl8195a/rtl_common.h"
#include "rtl8195a.h" #include "rtl8195a.h"
#include "lwip/opt.h" //#include "lwip/opt.h"
#include "netbios/netbios.h" #include "netbios/netbios.h"
#if LWIP_UDP /* don't build if not configured for use in lwipopts.h */ #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
@ -52,9 +52,9 @@
#define NETBIOS_CODE_ATTR #define NETBIOS_CODE_ATTR
#define NETBIOS_DATA_ATTR #define NETBIOS_DATA_ATTR
//extern struct netif xnetif[NET_IF_NUM]; extern struct netif xnetif[NET_IF_NUM];
#define NBS_DEF_NAME "rtl871x" #define NBS_DEF_NAME DEF_HOSTNAME
/** This is an example implementation of a NetBIOS name server. /** This is an example implementation of a NetBIOS name server.
* It responds to name queries for a configurable name. * It responds to name queries for a configurable name.
@ -163,6 +163,10 @@ PACK_STRUCT_END
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
//#define toupper(CH) \
// (((CH) >= 'a' && (CH) <= 'z') ? ((CH) - 'a' + 'A') : (CH))
/** NetBIOS decoding name */ /** NetBIOS decoding name */
static int8_t NETBIOS_CODE_ATTR NBNS_decode(char *dst, char *src) static int8_t NETBIOS_CODE_ATTR NBNS_decode(char *dst, char *src)
{ {
@ -346,41 +350,30 @@ bool NETBIOS_CODE_ATTR netbios_off(void) {
void NETBIOS_CODE_ATTR netbios_init(void) { void NETBIOS_CODE_ATTR netbios_init(void) {
struct udp_pcb *pcb; struct udp_pcb *pcb;
char buf[] = "a"NBS_DEF_NAME; char buf[NETBIOS_NAME_LEN];
#if NET_IF_NUM > 0
if (netbios_name[0][0] == 0) {
buf[0] = 'a'; // SoftAP
netbios_set_name(0, buf);
}
#endif
#if NET_IF_NUM > 1
if (netbios_name[1][0] == 0) {
buf[0] = 's'; // Station
netbios_set_name(1, buf);
}
#endif
#if NET_IF_NUM > 2
if (netbios_name[2][0] == 0) {
buf[0] = 'e'; // Ethernet
netbios_set_name(2, buf);
}
#endif
#if NET_IF_NUM > 3
#error "NBNS: Add NETBIOS Name!"
#endif
if (netbios_pcb() != NULL) if (netbios_pcb() != NULL)
return; return;
#if DEBUGSOO > 1 for(int i = 0; i < NET_IF_NUM; i++) {
#if NET_IF_NUM > 2 if (netbios_name[i][0] == 0) {
// os_printf("NetBIOS init, name AP: '%s', ST: '%s', Eth: '%s'\n", netbios_name[0], netbios_name[1], netbios_name[2]); #if LWIP_NETIF_HOSTNAME
os_printf("NetBIOS init, interface 0: '%s', 1: '%s', 2: '%s'\n", netbios_name[0], netbios_name[1], netbios_name[2]); if(xnetif[i].hostname != 0) {
#elif NET_IF_NUM > 1 netbios_set_name(i, xnetif[i].hostname);
// os_printf("NetBIOS init, name AP: '%s', ST: '%s'\n", netbios_name[0], netbios_name[1]); }
os_printf("NetBIOS init, interface 0: '%s', 1: '%s'\n", netbios_name[0], netbios_name[1]); else
#else
os_printf("NetBIOS init\n");
#endif #endif
{
sprintf(buf, NBS_DEF_NAME "%d", i);
netbios_set_name(i, buf);
};
};
};
#if DEBUGSOO > 1
os_printf("NetBIOS init, interface ");
for(int i = 0; i < NET_IF_NUM; i++) {
os_printf("%d: '%s' ", i, netbios_name[i]);
}
#endif #endif
pcb = udp_new(); pcb = udp_new();

View file

@ -1,6 +1,8 @@
#ifndef __NETBIOS_H__ #ifndef __NETBIOS_H__
#define __NETBIOS_H__ #define __NETBIOS_H__
#include "lwip/opt.h"
/** default port number for "NetBIOS Name service */ /** default port number for "NetBIOS Name service */
#define NETBIOS_PORT 137 #define NETBIOS_PORT 137
@ -15,7 +17,9 @@
extern "C" { extern "C" {
#endif #endif
//#if LWIP_NETIF_HOSTNAME
extern char netbios_name[NET_IF_NUM][NETBIOS_NAME_LEN + 1]; // default netifs/interfacenum: 0 - SoftAP, 1 - Station, 2 - Ethernet extern char netbios_name[NET_IF_NUM][NETBIOS_NAME_LEN + 1]; // default netifs/interfacenum: 0 - SoftAP, 1 - Station, 2 - Ethernet
//#endif
// struct udp_pcb * netbios_pcb(void); // struct udp_pcb * netbios_pcb(void);
void netbios_init(void); void netbios_init(void);

View file

@ -292,14 +292,15 @@ int sscanf(const char *buf, const char *fmt, ...) {
return i; return i;
} }
#define TOUPPER(CH) \ char toupper(char ch) {
(((CH) >= 'a' && (CH) <= 'z') ? ((CH) - 'a' + 'A') : (CH)) return ((ch >= 'a' && ch <= 'z') ? ch - 'a' + 'A' : ch);
};
int _stricmp (const char *s1, const char *s2) int _stricmp (const char *s1, const char *s2)
{ {
while (*s2 != 0 && TOUPPER (*s1) == TOUPPER (*s2)) while (*s2 != 0 && toupper(*s1) == toupper(*s2))
s1++, s2++; s1++, s2++;
return (int) (TOUPPER (*s1) - TOUPPER (*s2)); return (int) (toupper(*s1) - toupper(*s2));
} }
unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift) unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -70,6 +70,7 @@ RAM_IMAGE?= $(BIN_DIR)/ram.bin
RAM1_IMAGE ?= $(BIN_DIR)/ram_1.bin RAM1_IMAGE ?= $(BIN_DIR)/ram_1.bin
RAM1P_IMAGE ?= $(BIN_DIR)/ram_1.p.bin RAM1P_IMAGE ?= $(BIN_DIR)/ram_1.p.bin
RAM1R_IMAGE ?= $(BIN_DIR)/ram_1.r.bin
RAM2_IMAGE = $(BIN_DIR)/ram_2.bin RAM2_IMAGE = $(BIN_DIR)/ram_2.bin
RAM2P_IMAGE = $(BIN_DIR)/ram_2.p.bin RAM2P_IMAGE = $(BIN_DIR)/ram_2.p.bin
@ -97,10 +98,10 @@ all: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
mp: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin mp: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
copybin1: copybin1:
cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.r.bin $(BIN_DIR)/ram_1.r.bin # cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.r.bin $(BIN_DIR)/ram_1.r.bin
cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.p.bin $(BIN_DIR)/ram_1.p.bin cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.p.bin $(BIN_DIR)/ram_1.p.bin
# @chmod 777 $(OBJ_DIR)/ram_1.r.bin # @chmod 777 $(OBJ_DIR)/ram_1.r.bin
@$(OBJCOPY) --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm $(BIN_DIR)/ram_1.r.bin $(OBJ_DIR)/ram_1.r.o # @$(OBJCOPY) --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm $(BIN_DIR)/ram_1.r.bin $(OBJ_DIR)/ram_1.r.o
genbin1: $(ELFFILE) $(RAM1P_IMAGE) genbin1: $(ELFFILE) $(RAM1P_IMAGE)
@ -172,11 +173,11 @@ $(OTA_IMAGE): $(RAM2NS_IMAGE) $(RAM3_IMAGE)
$(RAM1P_IMAGE): $(ELFFILE) $(NMAPFILE) $(RAM1P_IMAGE): $(ELFFILE) $(NMAPFILE)
@echo "===========================================================" @echo "==========================================================="
@echo "Create image1p ($(RAM1P_IMAGE))" @echo "Create image1r ($(RAM1R_IMAGE))"
# @echo "===========================================================" .bootloader # @echo "===========================================================" .bootloader
ifdef COMPILED_BOOT ifdef COMPILED_BOOT
@mkdir -p $(BIN_DIR) @mkdir -p $(BIN_DIR)
@rm -f $(RAM1_IMAGE) $(RAM1P_IMAGE) @rm -f $(RAM1_IMAGE) $(RAM1R_IMAGE)
ifdef COMPILED_BOOT_BIN ifdef COMPILED_BOOT_BIN
@$(eval RAM1_START_ADDR := $(shell grep _binary_build_bin_ram_1_r_bin_start $(NMAPFILE) | awk '{print $$1}')) @$(eval RAM1_START_ADDR := $(shell grep _binary_build_bin_ram_1_r_bin_start $(NMAPFILE) | awk '{print $$1}'))
@$(eval RAM1_END_ADDR := $(shell grep _binary_build_bin_ram_1_r_bin_end $(NMAPFILE) | awk '{print $$1}')) @$(eval RAM1_END_ADDR := $(shell grep _binary_build_bin_ram_1_r_bin_end $(NMAPFILE) | awk '{print $$1}'))
@ -192,14 +193,14 @@ ifdef COMPILED_BOOT_BIN
else else
$(OBJCOPY) -j .rom_ram -Obinary $(ELFFILE) $(RAM_IMAGE) $(OBJCOPY) -j .rom_ram -Obinary $(ELFFILE) $(RAM_IMAGE)
$(OBJCOPY) -j .ram.start.table -j .ram_image1.text -Obinary $(ELFFILE) $(RAM1_IMAGE) $(OBJCOPY) -j .ram.start.table -j .ram_image1.text -Obinary $(ELFFILE) $(RAM1_IMAGE)
$(PICK) 0x$(RAM1_START_ADDR) 0x$(RAM1_END_ADDR) $(RAM1_IMAGE) $(RAM1P_IMAGE) head+reset_offset 0x0B000 $(PICK) 0x$(RAM1_START_ADDR) 0x$(RAM1_END_ADDR) $(RAM1_IMAGE) $(RAM1R_IMAGE) head+reset_offset 0x0B000
endif endif
else else
$(error "BOOT-image size = 0") $(error "BOOT-image size = 0")
# $(error Flasher: COMPILE_BOOT = No) # $(error Flasher: COMPILE_BOOT = No)
endif endif
else else
@if [ -s $(RAM1P_IMAGE) ]; then echo "Use external $(RAM1P_IMAGE)!"; fi @if [ -s $(RAM1R_IMAGE) ]; then echo "Use external $(RAM1R_IMAGE)!"; fi
endif endif
$(RAM2P_IMAGE): $(ELFFILE) $(NMAPFILE) $(RAM2P_IMAGE): $(ELFFILE) $(NMAPFILE)

View file

@ -64,6 +64,17 @@
#define IP_FRAG 1 #define IP_FRAG 1
#define ARP_QUEUEING 0 #define ARP_QUEUEING 0
/**
* LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname
* field.
*/
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETIF_HOSTNAME_SIZE 16
/**
* netif0: DEF_HOSTNAME "0", netif1: DEF_HOSTNAME "1", ..
*/
#define DEF_HOSTNAME "rtl871x"
/** /**
* NO_SYS==1: Provides VERY minimal functionality. Otherwise, * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
* use lwIP facilities. * use lwIP facilities.

View file

@ -50,7 +50,7 @@ application: build_info $(SRC_O) $(DRAM_O) $(BOOT_O)
# @echo "===========================================================" # @echo "==========================================================="
@mkdir -p $(BIN_DIR) $(OBJ_DIR) @mkdir -p $(BIN_DIR) $(OBJ_DIR)
## @cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.r.bin $(BIN_DIR)/ram_1.r.bin ## @cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.r.bin $(BIN_DIR)/ram_1.r.bin
## @cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.p.bin $(BIN_DIR)/ram_1.p.bin @cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.p.bin $(BIN_DIR)/ram_1.p.bin
# @chmod 777 $(OBJ_DIR)/ram_1.r.bin # @chmod 777 $(OBJ_DIR)/ram_1.r.bin
## $(OBJCOPY) --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm $(BIN_DIR)/ram_1.r.bin $(OBJ_DIR)/ram_1.r.o ## $(OBJCOPY) --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm $(BIN_DIR)/ram_1.r.bin $(OBJ_DIR)/ram_1.r.o
@echo "===========================================================" @echo "==========================================================="