Merge branch 'master' into master

This commit is contained in:
James YS Kim
2018-07-25 18:05:45 +09:00
committed by GitHub
7 changed files with 151 additions and 79 deletions

View File

@ -240,7 +240,8 @@ void (*dhcp_ip_conflict)(void) = default_ip_conflict; /* handler to be called
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
char NibbleToHex(uint8_t nibble);
/* send DISCOVER message to DHCP server */
void send_DHCP_DISCOVER(void);
@ -501,10 +502,13 @@ void send_DHCP_REQUEST(void)
pDHCPMSG->OPT[k++] = 0; // length of hostname
for(i = 0 ; HOST_NAME[i] != 0; i++)
pDHCPMSG->OPT[k++] = HOST_NAME[i];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4);
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname
pDHCPMSG->OPT[k++] = dhcpParamRequest;
pDHCPMSG->OPT[k++] = 0x08;
@ -944,7 +948,6 @@ void DHCP_init(uint8_t s, uint8_t * buf)
// WIZchip Netinfo Clear
setSIPR(zeroip);
setSIPR(zeroip);
setGAR(zeroip);
reset_DHCP_timeout();
@ -1002,6 +1005,13 @@ uint32_t getDHCPLeasetime(void)
return dhcp_lease_time;
}
char NibbleToHex(uint8_t nibble)
{
nibble &= 0x0F;
if (nibble <= 9)
return nibble + '0';
else
return nibble + ('A'-0x0A);
}

View File

@ -65,7 +65,7 @@
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
#define MAGIC_COOKIE 0x63825363 ///< Any number. You can be modifyed it any number
#define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.
#define DCHP_HOST_NAME "WIZnet\0"

View File

@ -133,6 +133,7 @@ uint8_t DNS_SOCKET; // SOCKET number for DNS
uint16_t DNS_MSGID; // DNS message ID
uint32_t dns_1s_tick; // for timout of DNS processing
static uint8_t retry_count;
/* converts uint16_t from network buffer to a host byte order integer. */
uint16_t get16(uint8_t * s)
@ -485,7 +486,6 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
int8_t check_DNS_timeout(void)
{
static uint8_t retry_count;
if(dns_1s_tick >= DNS_WAIT_TIME)
{
@ -519,6 +519,9 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
uint8_t ip[4];
uint16_t len, port;
int8_t ret_check_timeout;
retry_count = 0;
dns_1s_tick = 0;
// Socket open
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);

View File

@ -123,7 +123,7 @@ void NewNetwork(Network* n, int sn) {
* buffer : pointer to a read buffer.
* len : buffer length.
*/
int w5x00_read(Network* n, unsigned char* buffer, int len)
int w5x00_read(Network* n, unsigned char* buffer, int len, long time)
{
if((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket)>0))
@ -137,7 +137,7 @@ int w5x00_read(Network* n, unsigned char* buffer, int len)
* buffer : pointer to a read buffer.
* len : buffer length.
*/
int w5x00_write(Network* n, unsigned char* buffer, int len)
int w5x00_write(Network* n, unsigned char* buffer, int len, long time)
{
if(getSn_SR(n->my_socket) == SOCK_ESTABLISHED)
return send(n->my_socket, buffer, len);
@ -162,7 +162,7 @@ void w5x00_disconnect(Network* n)
*/
int ConnectNetwork(Network* n, char* ip, int port)
{
uint8_t myport = 12345;
uint16_t myport = 12345;
socket(n->my_socket,Sn_MR_TCP,myport,0);
connect(n->my_socket,ip,port);

View File

@ -251,8 +251,8 @@ int TimerLeftMS(Timer*);
/*
* @brief Network interface porting
*/
int w5x00_read(Network*, unsigned char*, int);
int w5x00_write(Network*, unsigned char*, int);
int w5x00_read(Network*, unsigned char*, int, long);
int w5x00_write(Network*, unsigned char*, int, long);
void w5x00_disconnect(Network*);
void NewNetwork(Network* n, int sn);
int ConnectNetwork(Network*, char*, int);