//---------------------------------------------------------------------------- //Verwaltung des TCP Timers void tcp_timer_call (void) { for (unsigned char index = 0;index<MAX_TCP_ENTRY;index++) { if (tcp_entry[index].time == 0) { if (tcp_entry[index].ip != 0) { tcp_entry[index].time = TCP_MAX_ENTRY_TIME; if ((tcp_entry[index].error_count++) > MAX_TCP_ERRORCOUNT) { DEBUG("Eintrag wird entfernt MAX_ERROR STACK:%i\r\n",index); ETH_INT_DISABLE; tcp_entry[index].status = RST_FLAG | ACK_FLAG; create_new_tcp_packet(0,index); ETH_INT_ENABLE; tcp_index_del(index); } else { DEBUG("Packet wird erneut gesendet STACK:%i\r\n",index); find_and_start (index); } } } else { if (tcp_entry[index].time != TCP_TIME_OFF) { tcp_entry[index].time--; } } } }
//---------------------------------------------------------------------------- //Daten kommen von einem Webserver an!! void test (unsigned char index) { for (int a = TCP_DATA_START_VAR;a < TCP_DATA_END_VAR;a++) { HTTPC_DEBUG("%c",eth_buffer[a]); } tcp_entry[index].time = TCP_TIME_OFF; tcp_entry[index].status = ACK_FLAG; create_new_tcp_packet(0,index); }
//---------------------------------------------------------------------------- //HTTP Request an einen Webserver stelle void http_request (void) { unsigned long index = MAX_TCP_ENTRY; if (http_get_state > 1 && http_get_state < 20) http_get_state++; if (http_get_state == 0) { //offnet eine Verbindung zu meinem Webserver HTTPC_DEBUG("ARP Request\n\r"); unsigned int my_http_cp = 2354; add_tcp_app (my_http_cp, (void(*)(unsigned char))test); //ARP Request senden if(arp_request (WEATHER_SERVER_IP)) { for(unsigned long a=0;a<2000000;a++){asm("nop");}; tcp_port_open (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80),LBBL_ENDIAN_INT(my_http_cp)); unsigned char tmp_counter = 0; while((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1)) { index = tcp_entry_search (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80)); if (tmp_counter++ > 30) { HTTPC_DEBUG("TCP Eintrag nicht gefunden (HTTP_CLIENT)!\r\n"); return; } } HTTPC_DEBUG("TCP Eintrag gefunden (HTTP_CLIENT)!\r\n"); tcp_entry[index].first_ack = 1; http_get_state = 2; } else { http_get_state = 1; } } //if (http_get_state == 10) if (http_get_state > 10 && http_get_state < 20) { HTTPC_DEBUG("\r\n\r\n\r\nDaten Anfordern\r\n"); index = tcp_entry_search (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80)); memcpy_P(ð_buffer[TCP_DATA_START],WEATHER_GET_STRING,(sizeof(WEATHER_GET_STRING)-1)); tcp_entry[index].status = ACK_FLAG | PSH_FLAG; create_new_tcp_packet((sizeof(WEATHER_GET_STRING)-1),index); } }
//---------------------------------------------------------------------------- //telnet Testserver void telnetd_send_data (void) { unsigned char index; if (rx_buffer_pointer_in != retransmission_pointer) { for (index = 0;index<MAX_TCP_ENTRY;index++) { if(tcp_entry[index].dest_port == LBBL_ENDIAN_INT(23)) { if(!telnetd_status.ack_wait) { telnetd_status.ack_wait = 1; unsigned int count = 0; retransmission_pointer = rx_buffer_pointer_out; while(rx_buffer_pointer_in != retransmission_pointer) { eth_buffer[TCP_DATA_START+count] = *retransmission_pointer++; count++; if (retransmission_pointer == &usart_rx_buffer[BUFFER_SIZE-1]) { retransmission_pointer = &usart_rx_buffer[0]; } } tcp_entry[index].status = ACK_FLAG | PSH_FLAG; create_new_tcp_packet(count,index); tcp_entry[index].time = TCP_MAX_ENTRY_TIME; return; } else { return; } } } if (index >= MAX_TCP_ENTRY) { if(usart_status.usart_disable) { usart_status.usart_disable = 0; } } } }
void notifications__run(void) { unsigned long index = MAX_TCP_ENTRY; if (http_get_state < 1) { HTTPC_DEBUG("httpc: ARP lookup for notification server\n\r"); unsigned int httpc__source_port = 2354; add_tcp_app(httpc__source_port, (void(*)(unsigned char))httpc_acknowledge); // Send ARP request if (arp_request(NOTIFICATIONS__SERVER_HOST)) { for(unsigned long a = 0;a < 2000000; a++) { asm("nop"); }; tcp_port_open(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT), htons(httpc__source_port)); unsigned char tmp_counter = 0; while ((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1)) { index = tcp_entry_search(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT)); if (tmp_counter++ > 30) { HTTPC_DEBUG("httpc: tcp entry not found!\r\n"); return; } } HTTPC_DEBUG("httpc: tcp entry found!\r\n"); tcp_entry[index].first_ack = 1; ++http_get_state; } else { ++http_get_state; } } else if (http_get_state == 20000) { HTTPC_DEBUG("httpc: sending HTTP request\r\n"); index = tcp_entry_search(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT)); memcpy_P(ð_buffer[TCP_DATA_START], PUT_REQUEST, (sizeof(PUT_REQUEST)-1)); tcp_entry[index].status = ACK_FLAG | PSH_FLAG; create_new_tcp_packet((sizeof(PUT_REQUEST)-1), index); http_get_state = 20001; } else if (http_get_state < 20000) http_get_state++; // wait.. ugly }
//---------------------------------------------------------------------------- //telnet Testserver void telnetd (unsigned char index) { TELNET_DEBUG("TELNET Anwendung gestartet\r\n"); //Verbindung wurde abgebaut! if (tcp_entry[index].status & FIN_FLAG) { usart_status.usart_disable = 0; return; } if (tcp_entry[index].app_status == 0 || tcp_entry[index].app_status == 1) { tcp_entry[index].app_status = 1; //memcpy_P(ð_buffer[TCP_DATA_START],PSTR("Start Telnet Server:\r\n"),22); //create_new_tcp_packet(22,index); usart_status.usart_disable = 1; telnetd_status.ack_wait = 0; tcp_entry[index].time = TCP_TIME_OFF; return; } if ((tcp_entry[index].app_status > 1) && (tcp_entry[index].status&PSH_FLAG)) { tcp_entry[index].app_status = 2; for (int a = TCP_DATA_START_VAR;a<(TCP_DATA_END_VAR);a++) { #if CMD_TELNET unsigned char receive_char; receive_char = eth_buffer[a]; if (receive_char == 0x08) { if (buffercounter) buffercounter--; } else if ((receive_char == '\r' || receive_char == '\n') && (!(usart_rx_buffer[buffercounter-1] == '\\'))) { usart_rx_buffer[buffercounter] = 0; buffercounter = 0; usart_status.usart_ready = 1; break; } else if (buffercounter < BUFFER_SIZE - 1) { usart_rx_buffer[buffercounter++] = receive_char; } #else #if !USE_CAM //Warten solange bis Zeichen gesendet wurde while(!(USR & (1<<UDRE))); //Ausgabe des Zeichens UDR = eth_buffer[a]; #endif #endif } tcp_entry[index].status = ACK_FLAG; create_new_tcp_packet(0,index); return; } //Ack erhalten vom gesendeten Packet if ((tcp_entry[index].app_status > 1)&&(tcp_entry[index].status&ACK_FLAG)&&(telnetd_status.ack_wait)) { tcp_entry[index].time = TCP_TIME_OFF; rx_buffer_pointer_out = retransmission_pointer; telnetd_status.ack_wait = 0; return; } //Time out kein ack angekommen if (tcp_entry[index].status == 0) { //Daten nochmal senden telnetd_status.ack_wait = 0; telnetd_send_data (); return; } return; }