void capture_start(GtkWidget *widget,gpointer data) { GtkWidget *isenable; uint8_t i = 0; guint text_len = 0; pthread_mutex_lock(&capture_state_mtx); if (capture_state == 0) capture_state = 1; pthread_mutex_unlock(&capture_state_mtx); init_file(); capture_packet(); pthread_mutex_lock(&packet_stat_mtx); tot_packet = 0; ip_packet = 0; tcp_packet = 0; udp_packet = 0; arp_packet = 0; icmp_packet = 0; igmp_packet = 0; capture_pre_packet = 0; pthread_mutex_unlock(&packet_stat_mtx); isenable = capture_menu[0].widget; gtk_widget_set_sensitive(isenable,FALSE); isenable = capture_menu[1].widget; gtk_widget_set_sensitive(isenable,TRUE); gtk_clist_clear((GtkCList *)clist); for (i = 0;i < 5;i++) { if (item[i]) { gtk_tree_item_remove_subtree((GtkTreeItem *)item[i]); gtk_container_remove (GTK_CONTAINER(tree), item[i]); item[i] = NULL; } } gtk_text_freeze(GTK_TEXT(hex_text)); text_len = gtk_text_get_length(GTK_TEXT(hex_text)); gtk_text_backward_delete(GTK_TEXT(hex_text),text_len); gtk_text_thaw(GTK_TEXT(hex_text)); gtk_text_freeze(GTK_TEXT(hex_text)); text_len = gtk_text_get_length(GTK_TEXT(hex_text)); gtk_text_backward_delete(GTK_TEXT(hex_text),text_len); gtk_text_thaw(GTK_TEXT(hex_text)); }
//handle our packets. void process_host_packets() { unsigned long start = millis(); unsigned long end = start + PACKET_TIMEOUT; #ifdef ENABLE_COMMS_DEBUG //Serial.print("IN: "); #endif //do we have a finished packet? while (!hostPacket.isFinished()) { if (Serial.available() > 0) { //digitalWrite(DEBUG_PIN, HIGH); //grab a byte and process it. byte d; d = Serial.read(); hostPacket.process_byte(d); #ifdef ENABLE_COMMS_DEBUG //Serial.print(d, HEX); //Serial.print(" "); #endif serial_rx_count++; //keep us goign while we have data coming in. start = millis(); end = start + PACKET_TIMEOUT; if (hostPacket.getResponseCode() == RC_CRC_MISMATCH) { //host_crc_errors++; digitalWrite(DEBUG_PIN, HIGH); #ifdef ENABLE_COMMS_DEBUG Serial.println("Host CRC Mismatch"); #endif } } //are we sure we wanna break mid-packet? //have we timed out? if (millis() >= end) { #ifdef ENABLE_COMMS_DEBUG Serial.println("Host timeout"); #endif break; } } if (hostPacket.isFinished()) { serial_packet_count++; byte b = hostPacket.get_8(0); // top bit high == bufferable command packet (eg. #128-255) if (b & 0x80) { if (is_capturing()) { // Capture this to the SD card capture_packet(hostPacket); } else { //do we have room? if (commandBuffer.remainingCapacity() >= hostPacket.getLength()) { //okay, throw it in the buffer. for (byte i=0; i<hostPacket.getLength(); i++) commandBuffer.append(hostPacket.get_8(i)); } else { // Otherwise, we go on with an overflow packet. hostPacket.overflow(); } } } // top bit low == reply needed query packet (eg. #0-127) else handle_query(b); } //okay, send our response hostPacket.sendReply(); }