weAutSys provides Ethernet / LAN communication based on
These are the basic functions for all application (support) layers weAutSys supports. There upon application software may implement further protocols and networking applications.
Files | |
file | network.h |
weAutSys' (low level) system calls, services and types for LAN / Ethernet communication | |
Data Structures | |
struct | ipConf_t |
The IP configuration. More... | |
Defines | |
#define | BUF2EH |
The uip buffer cast to Ethernet header. | |
#define | DHCP_MSK |
Mask for DHCP (use / set by) bit. | |
#define | DNS1_MSK |
Mask for DNS server 1 set bit. | |
#define | DNS2_MSK |
Mask for DNS server 2 set bit. | |
#define | DNS_CLIENT_MSK |
Mask for be DNS client bit. | |
#define | DNS_MSK |
Mask for DNS servers (set / use if set) bits. | |
#define | ECHO_PORT 7 |
The well known Echo port. | |
#define | ENC_HWP |
Mask for the ENC HW problem bit in networkNotReady. | |
#define | ENC_MSK |
Mask for the ENC bits in networkNotReady. | |
#define | ENC_NRD |
Mask for the ENC not ready bit in networkNotReady. | |
#define | ENC_PWS |
Mask for the ENC powersave bit in networkNotReady. | |
#define | IP_ADD(addr0, addr1, addr2, addr3) |
Initializer of an IP (V4) address from four byte values. | |
#define | IPBUF |
The uip buffer cast to Ethernet IP header. | |
#define | LNC_IDN |
Mask for the link is down (at last status request) in networkNotReady. | |
#define | LNC_WDN |
Mask for the link was down (before last status request) in networkNotReady. | |
#define | MODBUS_PORT 502 |
The well known Modbus port. | |
#define | NTP1_MSK |
Mask for NTP server 1 set bit. | |
#define | NTP2_MSK |
Mask for NTP server 2 set bit. | |
#define | NTP_CLIENT_MSK |
Mask for be NTP client bit. | |
#define | NTP_MSK |
Mask for NTP server bits. | |
#define | NTP_SERVERT_MSK |
Mask for be NTP server bit. | |
#define | STC_MSK |
Mask for the stack bits in networkNotReady. | |
#define | STC_NST |
Mask for the stack' IP not set bit in networkNotReady. | |
#define | TELNET_PORT 23 |
The well known Telnet port. | |
Typedefs | |
typedef struct uip_eth_addr | eth_addr_t |
Representation of a 48-bit Ethernet address / MAC address. | |
Functions | |
uint16_t | deviceDriverPoll (void) |
Hand over received packages. | |
void | deviceDriverSend (void) |
Send the actual uIP buffer. | |
struct uip_eth_addr * | getMACforIPaddr (uip_ipaddr_t ipAddr) |
Get the MAC address for an IP address. | |
uint8_t | linkState (void) |
Check the link state. | |
void | networkPolling (void) |
Receive and then perhaps send the actual uIP buffer. | |
ptfnct_t | outEncLanInfoThreadF (hierThr_data_t *threadD, FILE *toStream) |
Output Ethernet and driver (ENC28J60) state info, the thread function. | |
void | setMACadd (eth_addr_t *mac) |
Set the IP stack's MAC address. | |
void | setMACaddP (const eth_addr_t *mac) |
Set the stack's MAC address. | |
void | udpAppcall (void) |
The uIP udp event function for the application software. | |
void | uipAppcall (void) |
The uIP event function for the application software. | |
void | uipGetAddresses (ipConf_t *ipConf) |
Get the addresses from the uIP stack. | |
void | uipSetAddresses (ipConf_t *ipConf) |
Set the addresses in the uIP stack. | |
Variables | |
uint8_t | arpTickPeriod |
The period of the ARP timeout tick in seconds. | |
uint8_t | arpTimeOut |
The ARP timeout counter in seconds. | |
ipConf_t | curIpConf |
The actual IP configuration. | |
uint8_t | networkNotReady |
Network not ready. |
#define IP_ADD | ( | addr0, | |
addr1, | |||
addr2, | |||
addr3 | |||
) |
Initializer of an IP (V4) address from four byte values.
This function constructs an {embraced} initialiser for an uip_ipaddr_t (array) type.
Example:
uip_ipaddr_t defaultIPaddr = IPADD(192, 168, 89, 31);
will result in the correct array initialisation in network byte order (big endian).
addr0 | The first octet of the IP address |
addr1 | The second octet |
addr2 | The third octet |
addr3 | The forth octet |
#define DHCP_MSK |
#define DNS1_MSK |
#define DNS_CLIENT_MSK |
Mask for be DNS client bit.
#define NTP_CLIENT_MSK |
#define NTP_SERVERT_MSK |
Mask for be NTP server bit.
#define BUF2EH |
The uip buffer cast to Ethernet header.
This macro provides the buffer uip_buf as type uip_eth_hdr .
#define IPBUF |
typedef struct uip_eth_addr eth_addr_t |
Representation of a 48-bit Ethernet address / MAC address.
This is uIP's type uip_eth_addr defined in uip.h holding an array uint8_t addr[6] in the end.
addr[0] would be octet [1] of the MAC address defining
Bit 0 = 0: unicast / = 1: multi/broadcast address
Bit 1 = 0: manufacturer / =1: locally assigned address
void setMACadd | ( | eth_addr_t * | mac | ) |
Set the IP stack's MAC address.
This sets the the Ethernet stack's i.e. uIP's MAC address but not the driver's ( ENC28J60).
Of course, the driver's MAC setting has to be same. This is done by encSetMacAdd(), encInit() or networkInit().
mac | pointer to a structure (in RAM) holding the new MAC address |
void setMACaddP | ( | const eth_addr_t * | mac | ) |
Set the stack's MAC address.
This is the same as setMACadd except for the new MAC address structure held in program (flash) memory
mac | pointer to a structure (in flash) holding the new MAC address |
void uipSetAddresses | ( | ipConf_t * | ipConf | ) |
Set the addresses in the uIP stack.
This function takes the fields ipAddr, netMask, defaultRouter and dnsAddr and makes the appropriate settings in the uIP stack. The bit 4 ("stack's IP is not yet set") is cleared in networkNotReady.
ipConf's
cFlags is irrelevant: the settings are made even if the flag says "use DHCP". Hence ipConf
must not be null and it must have correct entries for ipAddr
, netMask
and defaultRouter
.
ipConf | pointer to the source of the addresses and masks |
void uipGetAddresses | ( | ipConf_t * | ipConf | ) |
Get the addresses from the uIP stack.
This function fills the fields ipAddr, netMask, defaultRouter and dnsAddr from the respective settings in the uIP stack.
ipConf's cFlags is left unchanged.
ipConf | pointer to the destination of the addresses and masks |
void deviceDriverSend | ( | void | ) |
void networkPolling | ( | void | ) |
Receive and then perhaps send the actual uIP buffer.
This is standard control structure around calling uip_input as described in the uIP documentation in one function.
To have all this in one block by calling this function may be questionable. It will be put in (pieces in) appropriate threads. And as of this writing this function was not used yet.
uint16_t deviceDriverPoll | ( | void | ) |
Hand over received packages.
This function checks if the network driver IC (NIC), an ENC28J60 in case of weAut_01, has received a package. If so it is copied to uIP's uip_buf and the number of bytes is returned.
See function devicedriver_poll respectively ethernetdevicedrver_poll in uIP documentation.
ptfnct_t outEncLanInfoThreadF | ( | hierThr_data_t * | threadD, |
FILE * | toStream | ||
) |
Output Ethernet and driver (ENC28J60) state info, the thread function.
This thread will output some info on Ethernet and driver configuration and state to toStream
(as standard output).
This thread function acts on threadD's secondary thread and secondary flag. flag2's
bits signal which informations are to be output:
Bit 0 : MAC
Bit 1 : current IP setting
Bit 2 : default IP setting
Bit 3 : ARP
Bit 4 : Link state
Bit 5 : DHCP state
As secondary thread it will usually be started as the primary threads child.
threadD | the thread state data (pointer to; not NULL) |
toStream | streams to switch the standard streams to (if not MULL) |
uint8_t linkState | ( | void | ) |
Check the link state.
This function checks the actual link state and sets the relevant bits (LNC_IDN and LNC_WDN) in networkNotReady.
struct uip_eth_addr* getMACforIPaddr | ( | uip_ipaddr_t | ipAddr | ) | [read] |
Get the MAC address for an IP address.
This function checks the ARP table for an entry about ipAddr and returns the (pointer to its) MAC address.
The caller must not manipulate the returned MAC.
ipAddr | IP address the MAC is to be determined for |
void udpAppcall | ( | void | ) |
The uIP udp event function for the application software.
The reason for being called will be in the uip_udp_conn
structure, especially in the ports.
This function will be called for events, ports etc. not handled by system software (like NTP or DHCP e.g.).
If no extra protocols are implemented by user / application software the implementation should do nothing (but return
; ).
Otherwise it is best to use (at least) the remote port to distribute to different protocol handling functions (best being protothreads). Client example:
void udpAppcall(void){ if(uip_udp_conn->rport == HTONS(MTP_PORT)) { // MTP protocol mtpAppcall(); // protothread function / state machine handling MTP return; } // MTP protocol if(uip_udp_conn->rport == HTONS(THCPC_SERVER_PORT)) { // THCP protocol thcpc_appcall(); // protothread function / state machine handling THCP return; } // THCP protocol (client) // add further protocols here } // udpAppcall()
void uipAppcall | ( | void | ) |
The uIP event function for the application software.
The reason for being called will be in uip_flags
.
This function will be called for events, ports etc. not handled by system software.
If no extra protocols are implemented by user / application software the implementation should do nothing (but return
; ).
Otherwise it is best to use (at least) the local port to distribute to different protocol handlers. The handlers would best be implemented as protothread functions using appropriate appstate
fields in the uip_conn
as state.
The server example is simplified (i.e. stateless):
void uipAppcall(void){ // for state use something // like : struct cliThr_data_t *s = (cliThr_data_t *)&(uip_conn->appstate); if(uip_conn->lport == HTONS(7) // Echo protocol .. and && (uip_newdata() || uip_acked())) { // new (or ack'ed) data uip_send(uip_appdata, uip_datalen()); return; } // echo server (new data only) // add further handling and protocols here } // uipAppcall()
uint8_t arpTickPeriod |
The period of the ARP timeout tick in seconds.
The standard / default value is 10. User / application software might set a higher value to reduce ARP µController load.
uint8_t arpTimeOut |
The ARP timeout counter in seconds.
This counter is decremented every second. At 0 it is reset to arpTickPeriod and uip_arp_timer() is called. The latter uIP function handles the aging of ARP entries.
uint8_t networkNotReady |
Network not ready.
If this state flag 0x00 means the network is ready.
One of the lower four bits stands for a network state or problem that impedes communication.
The upper four bits do the same for the hardware driver, which in the case of weAut_01 it is an ENC28J60.
Bit 7 : ENC is not initialised yet / was reset (mask ENC_NRD)
Bit 6 : ENC has hardware (CLKRDY) trouble (mask ENC_HWP)
Bit 5 : ENC is in power save (PWRSV) mode (mask ENC_PWS)
Bit 3 : stack's IP is not yet set / determined (by DHCP e.g., mask STC_NST)
Bit 2 : link is down (status of last last request by e.g. linkState(), mask LNC_IDN)
Bit 1 : link was down (status before last last request by e.g. linkState(), mask LNC_WDN)