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_util.h>
rtw_mode_t wifi_mode = RTW_MODE_STA;
extern rtw_mode_t wifi_mode; // = RTW_MODE_STA;
#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);
}
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.
* @param None.

View file

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

View file

@ -2,9 +2,17 @@
#define __ETHERNETIF_H__
#include "autoconf.h"
#include "lwip/err.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
//----- ------------------------------------------------------------------

View file

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

View file

@ -36,7 +36,7 @@
#include "rtl8195a/rtl_common.h"
#include "rtl8195a.h"
#include "lwip/opt.h"
//#include "lwip/opt.h"
#include "netbios/netbios.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_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.
* It responds to name queries for a configurable name.
@ -163,6 +163,10 @@ PACK_STRUCT_END
# include "arch/epstruct.h"
#endif
//#define toupper(CH) \
// (((CH) >= 'a' && (CH) <= 'z') ? ((CH) - 'a' + 'A') : (CH))
/** NetBIOS decoding name */
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) {
struct udp_pcb *pcb;
char buf[] = "a"NBS_DEF_NAME;
#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
char buf[NETBIOS_NAME_LEN];
if (netbios_pcb() != NULL)
return;
#if DEBUGSOO > 1
#if NET_IF_NUM > 2
// os_printf("NetBIOS init, name AP: '%s', ST: '%s', Eth: '%s'\n", netbios_name[0], netbios_name[1], netbios_name[2]);
os_printf("NetBIOS init, interface 0: '%s', 1: '%s', 2: '%s'\n", netbios_name[0], netbios_name[1], netbios_name[2]);
#elif NET_IF_NUM > 1
// 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
os_printf("NetBIOS init\n");
for(int i = 0; i < NET_IF_NUM; i++) {
if (netbios_name[i][0] == 0) {
#if LWIP_NETIF_HOSTNAME
if(xnetif[i].hostname != 0) {
netbios_set_name(i, xnetif[i].hostname);
}
else
#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
pcb = udp_new();

View file

@ -1,6 +1,8 @@
#ifndef __NETBIOS_H__
#define __NETBIOS_H__
#include "lwip/opt.h"
/** default port number for "NetBIOS Name service */
#define NETBIOS_PORT 137
@ -15,7 +17,9 @@
extern "C" {
#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
//#endif
// struct udp_pcb * netbios_pcb(void);
void netbios_init(void);

View file

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