Gast
#4219334
Hallo,
ich habe folgende Problem:
ich will mit einem XMEGA-Mikrocontroller sowohl über UDP DHCP
realisieren als auch mit UDP die Zeit über NTP holen.
Nun ist es so, dass nach DHCP-INIT und dem darauffolgenden
Verbindungsaufbau mit der DHCP-Prozedur auf PORT 67/68 nicht mehr eine
neue Verbindung für NTP aufgebaut werden kann auf PORT 123.
CODE:
void dhcp_init(void)
{
uip_ipaddr_t addr;
// initially, the IP-Address must be 0.0.0.0
// otherwise the DHCP server would NAK the request
uip_ipaddr(addr, 0, 0, 0, 0);
uip_sethostaddr(addr);
status.state = DHCP_STATE_INITIAL;
// Destination is the broadcast address
uip_ipaddr(addr, 255, 255, 255, 255);
status.conn = uip_udp_new(&addr, HTONS(dhcp_SERVER_PORT));
if (status.conn != NULL) {
uip_udp_bind(status.conn, HTONS(dhcp_CLIENT_PORT));
}
PT_INIT(&status.pt);
}
hier wird also eine neue Verbindung eingerichtet um eine IP zu beziehen
vom Server PORT67 zum Clienten Clienten PORT68
Danach kommt die NTP-INIT:
CODE:
static struct uip_udp_conn *ntp_conn = NULL;
void ntp_init(void)
{
static uint16_t ntpIP_tmp[4];
ntpstat.state = STATE_IDLE;
nvm_eeprom_read_buffer(0x112, ntpIP, 4);
memmove(&ntpIP_tmp[0], (uint8_t *)&ntpIP , 1);
memmove(&ntpIP_tmp[1], (uint8_t *)&ntpIP + 1, 1);
memmove(&ntpIP_tmp[2], (uint8_t *)&ntpIP + 2, 1);
memmove(&ntpIP_tmp[3], (uint8_t *)&ntpIP + 3, 1);
if(ntpIP_tmp[0] == 0xFF && ntpIP_tmp[1] == 0xFF
&& ntpIP_tmp[2] == 0xFF && ntpIP_tmp[3] == 0xFF)
{
uip_ipaddr(ntpIP, 134,130,4,17);
nvm_eeprom_erase_and_write_buffer(0x112, ntpIP, 4);
}
if(ntp_conn != NULL) {
uip_udp_remove(ntp_conn);
}
ntp_conn = uip_udp_new(&ntpIP, HTONS(123));
if(ntp_conn != NULL) {
uip_udp_bind(ntp_conn, HTONS(123)); }
}
Danach wird bei bestehenden UDP-Verbindungen die folgende Funktion
aufgerufen, um die UDP-Verbindungen zu dispatchen anhand der PORTS
void udp_appcall(void)
{
if(uip_udp_conn->rport == HTONS(123)) { // NTP protocol
ntp_appcall();
}
if((uip_udp_conn->rport == HTONS(67)) || (uip_udp_conn->lport ==
HTONS(68)))
{ // NTP protocol
dhcp_appcall();
}
}
Die DHCP-Prozedur kann erfolgreich eine IP beziehen und eine Verbindung
aufbauen, aber danach kann keine NTP-Zeit mehr geholt werden mit NTP.
Ohne DHCP, also statischer IP, funktioniert die NTP-Zeitabfrage über
UDP.
Was läuft hier falsch. Übrigens die NTP-INIT kommt direkt nach
DHCP-Init. Ist also möglicherweise die NTP-Init fehlgeschlagen oder muss
vorher die DHCP-Verbindung explizit beenden werden?
Oder muss wegen DHCP überhaupt eine permanente Verbindung zum Router
bestehen.
Ich hoffe hier kennt sich jemand aus mit solchen Netzwerksachen.