diff options
author | David Brodski <david@brodski.eu> | 2011-04-04 20:21:18 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-04-04 20:21:18 +0000 |
commit | a3a48fc5c962de3953ed2cca4512e23349477515 (patch) | |
tree | e6628c541ed0795507d6ed3dc944f33f21405009 /src/transport/plugin_transport_wlan.c | |
parent | b3e8ee62381ead509fdac94482f1dab9a832106f (diff) | |
download | gnunet-a3a48fc5c962de3953ed2cca4512e23349477515.tar.gz gnunet-a3a48fc5c962de3953ed2cca4512e23349477515.zip |
CodeSonar errors fixed
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 99 |
1 files changed, 64 insertions, 35 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 9613121c8..a305d0df6 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -1098,7 +1098,9 @@ sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm) | |||
1098 | if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, fm->next_ack).rel_value | 1098 | if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, fm->next_ack).rel_value |
1099 | == 0) | 1099 | == 0) |
1100 | { | 1100 | { |
1101 | break; | 1101 | GNUNET_CONTAINER_DLL_insert_before(plugin->pending_Fragment_Messages_head, |
1102 | plugin->pending_Fragment_Messages_tail,fm2,fm); | ||
1103 | return; | ||
1102 | } | 1104 | } |
1103 | else | 1105 | else |
1104 | { | 1106 | { |
@@ -1106,8 +1108,8 @@ sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm) | |||
1106 | } | 1108 | } |
1107 | } | 1109 | } |
1108 | 1110 | ||
1109 | GNUNET_CONTAINER_DLL_insert_after(plugin->pending_Fragment_Messages_head, | 1111 | GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head, |
1110 | plugin->pending_Fragment_Messages_tail,fm2,fm); | 1112 | plugin->pending_Fragment_Messages_tail,fm); |
1111 | } | 1113 | } |
1112 | 1114 | ||
1113 | /** | 1115 | /** |
@@ -1602,7 +1604,6 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1602 | if (bytes != finish->size) | 1604 | if (bytes != finish->size) |
1603 | { | 1605 | { |
1604 | 1606 | ||
1605 | finish->plugin = plugin; | ||
1606 | finish->msgheader = finish->msgheader + bytes; | 1607 | finish->msgheader = finish->msgheader + bytes; |
1607 | finish->size = finish->size - bytes; | 1608 | finish->size = finish->size - bytes; |
1608 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( | 1609 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( |
@@ -1623,9 +1624,16 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session, | |||
1623 | struct Radiotap_Send * header) | 1624 | struct Radiotap_Send * header) |
1624 | { | 1625 | { |
1625 | 1626 | ||
1626 | header->rate = session->rate; | 1627 | if (session != null){ |
1627 | header->tx_power = session->tx_power; | 1628 | header->rate = session->rate; |
1628 | header->antenna = session->antenna; | 1629 | header->tx_power = session->tx_power; |
1630 | header->antenna = session->antenna; | ||
1631 | } else { | ||
1632 | header->rate = 255; | ||
1633 | header->tx_power = 0; | ||
1634 | header->antenna = 0; | ||
1635 | } | ||
1636 | |||
1629 | return GNUNET_YES; | 1637 | return GNUNET_YES; |
1630 | } | 1638 | } |
1631 | ; | 1639 | ; |
@@ -1996,10 +2004,6 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) | |||
1996 | /* TODO check for bad addresses like multicast, broadcast, etc */ | 2004 | /* TODO check for bad addresses like multicast, broadcast, etc */ |
1997 | return GNUNET_OK; | 2005 | return GNUNET_OK; |
1998 | } | 2006 | } |
1999 | else | ||
2000 | { | ||
2001 | return GNUNET_SYSERR; | ||
2002 | } | ||
2003 | 2007 | ||
2004 | return GNUNET_SYSERR; | 2008 | return GNUNET_SYSERR; |
2005 | } | 2009 | } |
@@ -2090,12 +2094,12 @@ static void | |||
2090 | insert_fragment_in_queue(struct Receive_Message_Queue * rec_message, | 2094 | insert_fragment_in_queue(struct Receive_Message_Queue * rec_message, |
2091 | struct Receive_Fragment_Queue * rec_queue) | 2095 | struct Receive_Fragment_Queue * rec_queue) |
2092 | { | 2096 | { |
2093 | struct Receive_Fragment_Queue * rec_queue2 = rec_message->frag_head; | ||
2094 | struct WlanHeader * wlanheader = NULL; | ||
2095 | |||
2096 | GNUNET_assert(rec_message != NULL); | 2097 | GNUNET_assert(rec_message != NULL); |
2097 | GNUNET_assert(rec_queue != NULL); | 2098 | GNUNET_assert(rec_queue != NULL); |
2098 | 2099 | ||
2100 | struct Receive_Fragment_Queue * rec_queue2 = rec_message->frag_head; | ||
2101 | struct WlanHeader * wlanheader = NULL; | ||
2102 | |||
2099 | //this is the first fragment of the message (fragment id 0) | 2103 | //this is the first fragment of the message (fragment id 0) |
2100 | if (rec_queue->num == 0) | 2104 | if (rec_queue->num == 0) |
2101 | { | 2105 | { |
@@ -2165,6 +2169,8 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2165 | struct Session_light * session_light, struct Session * session, | 2169 | struct Session_light * session_light, struct Session * session, |
2166 | struct Receive_Message_Queue * rec_message) | 2170 | struct Receive_Message_Queue * rec_message) |
2167 | { | 2171 | { |
2172 | GNUNET_assert(rec_message !=NULL); | ||
2173 | |||
2168 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; | 2174 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; |
2169 | int packetsize = rec_message->rec_size; | 2175 | int packetsize = rec_message->rec_size; |
2170 | int sum = 0; | 2176 | int sum = 0; |
@@ -2172,12 +2178,23 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2172 | uint64_t bitfield = 0; | 2178 | uint64_t bitfield = 0; |
2173 | char * msg; | 2179 | char * msg; |
2174 | 2180 | ||
2175 | GNUNET_assert(rec_message !=NULL); | ||
2176 | //check if first fragment is present | 2181 | //check if first fragment is present |
2177 | if (packetsize == MESSAGE_LENGHT_UNKNOWN) | 2182 | if (packetsize == MESSAGE_LENGHT_UNKNOWN) |
2178 | { | 2183 | { |
2179 | return; | 2184 | return; |
2180 | } | 2185 | } |
2186 | // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader | ||
2187 | else if (packetsize < sizeof(struct WlanHeader) | ||
2188 | + sizeof(struct GNUNET_MessageHeader)) | ||
2189 | { | ||
2190 | #if DEBUG_wlan | ||
2191 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2192 | "Message not big enough\n"); | ||
2193 | #endif | ||
2194 | free_receive_message(plugin, rec_message); | ||
2195 | return; | ||
2196 | } | ||
2197 | |||
2181 | #if DEBUG_wlan | 2198 | #if DEBUG_wlan |
2182 | check_message_fragment_bitfield(rec_message); | 2199 | check_message_fragment_bitfield(rec_message); |
2183 | #endif | 2200 | #endif |
@@ -2278,6 +2295,13 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2278 | ntohs(hdr->size)); | 2295 | ntohs(hdr->size)); |
2279 | #endif | 2296 | #endif |
2280 | 2297 | ||
2298 | if (ntohs(hdr->size) < sizeof(struct WlanHeader) | ||
2299 | + sizeof(struct GNUNET_MessageHeader)) | ||
2300 | { | ||
2301 | //packet not big enought | ||
2302 | return; | ||
2303 | } | ||
2304 | |||
2281 | GNUNET_assert(session_light != NULL); | 2305 | GNUNET_assert(session_light != NULL); |
2282 | if (session_light->session == NULL) | 2306 | if (session_light->session == NULL) |
2283 | { | 2307 | { |
@@ -2285,6 +2309,7 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2285 | } | 2309 | } |
2286 | session = session_light->session; | 2310 | session = session_light->session; |
2287 | wlanheader = (struct WlanHeader *) hdr; | 2311 | wlanheader = (struct WlanHeader *) hdr; |
2312 | |||
2288 | tempmsg = (char*) &wlanheader[1]; | 2313 | tempmsg = (char*) &wlanheader[1]; |
2289 | temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; | 2314 | temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; |
2290 | 2315 | ||
@@ -2677,7 +2702,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2677 | { | 2702 | { |
2678 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 2703 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2679 | "WLAN fragment not in fragment list with id %u of ack\n", ntohl( | 2704 | "WLAN fragment not in fragment list with id %u of ack\n", ntohl( |
2680 | fh->message_id)); | 2705 | fah->message_id)); |
2681 | return; | 2706 | return; |
2682 | } | 2707 | } |
2683 | 2708 | ||
@@ -2794,7 +2819,7 @@ wlan_process_helper (void *cls, | |||
2794 | #if DEBUG_wlan | 2819 | #if DEBUG_wlan |
2795 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2820 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2796 | "Func wlan_process_helper got wrong MAC: %s\n", macprinter( | 2821 | "Func wlan_process_helper got wrong MAC: %s\n", macprinter( |
2797 | wlanIeeeHeader->i_addr1)); | 2822 | wlanIeeeHeader->i_addr1)); |
2798 | #endif | 2823 | #endif |
2799 | } | 2824 | } |
2800 | } | 2825 | } |
@@ -3005,13 +3030,29 @@ libgnunet_plugin_transport_wlan_init(void *cls) | |||
3005 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 3030 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
3006 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; | 3031 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; |
3007 | 3032 | ||
3008 | set_next_beacon_time(plugin); | 3033 | plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, |
3034 | plugin); | ||
3035 | |||
3036 | plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); | ||
3037 | |||
3038 | //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); | ||
3039 | //plugin->pending_Sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); | ||
3040 | |||
3041 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | ||
3042 | api->cls = plugin; | ||
3043 | api->send = &wlan_plugin_send; | ||
3044 | api->disconnect = &wlan_plugin_disconnect; | ||
3045 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | ||
3046 | api->check_address = &wlan_plugin_address_suggested; | ||
3047 | api->address_to_string = &wlan_plugin_address_to_string; | ||
3048 | |||
3049 | //read config | ||
3009 | 3050 | ||
3010 | if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE")) | 3051 | if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE")) |
3011 | { | 3052 | { |
3012 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg, | 3053 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg, |
3013 | "transport-wlan", "TESTMODE", &testmode)) | 3054 | "transport-wlan", "TESTMODE", &testmode)) |
3014 | return NULL; | 3055 | testmode = 0; //default value |
3015 | } | 3056 | } |
3016 | 3057 | ||
3017 | if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE")) | 3058 | if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE")) |
@@ -3019,27 +3060,15 @@ libgnunet_plugin_transport_wlan_init(void *cls) | |||
3019 | if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan", | 3060 | if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan", |
3020 | "INTERFACE", &(plugin->interface)) != GNUNET_YES) | 3061 | "INTERFACE", &(plugin->interface)) != GNUNET_YES) |
3021 | { | 3062 | { |
3022 | libgnunet_plugin_transport_wlan_done(plugin); | 3063 | libgnunet_plugin_transport_wlan_done(api); |
3023 | return NULL; | 3064 | return NULL; |
3024 | } | 3065 | } |
3025 | } | 3066 | } |
3026 | 3067 | ||
3027 | wlan_transport_start_wlan_helper(plugin, testmode); | 3068 | //start the plugin |
3028 | plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, | 3069 | set_next_beacon_time(plugin); |
3029 | plugin); | ||
3030 | |||
3031 | plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); | ||
3032 | |||
3033 | //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); | ||
3034 | //plugin->pending_Sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); | ||
3035 | 3070 | ||
3036 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3071 | wlan_transport_start_wlan_helper(plugin, testmode); |
3037 | api->cls = plugin; | ||
3038 | api->send = &wlan_plugin_send; | ||
3039 | api->disconnect = &wlan_plugin_disconnect; | ||
3040 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | ||
3041 | api->check_address = &wlan_plugin_address_suggested; | ||
3042 | api->address_to_string = &wlan_plugin_address_to_string; | ||
3043 | 3072 | ||
3044 | start_next_message_id(); | 3073 | start_next_message_id(); |
3045 | 3074 | ||