diff options
author | Campus <campus@ntop.org> | 2016-12-15 12:15:48 +0100 |
---|---|---|
committer | Campus <campus@ntop.org> | 2016-12-15 12:15:48 +0100 |
commit | 61f0eb062ef489cebba21c6c866b47a879d01a24 (patch) | |
tree | f2fd16f1ecd9494c43214707f6dabe4022493b1d /src | |
parent | b68f197fea206f121f6cb94dbb5decc7a7a99491 (diff) |
fix indent code and int type to keep conformity of the rest of the code (u_intxx instead uintxx)
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/protocols/smpp.c | 506 |
1 files changed, 253 insertions, 253 deletions
diff --git a/src/lib/protocols/smpp.c b/src/lib/protocols/smpp.c index de50f9427..a511d2089 100644 --- a/src/lib/protocols/smpp.c +++ b/src/lib/protocols/smpp.c @@ -1,23 +1,23 @@ /* -* smpp.c -* -* Copyright (C) 2016 - Damir Franusic <df@release14.org> -* Copyright (C) 2016 - ntop.org -* -* nDPI is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* nDPI is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with nDPI. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * smpp.c + * + * Copyright (C) 2016 - Damir Franusic <df@release14.org> + * Copyright (C) 2016 - ntop.org + * + * nDPI is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nDPI is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with nDPI. If not, see <http://www.gnu.org/licenses/>. + * + */ #include "ndpi_protocols.h" @@ -39,266 +39,266 @@ void ndpi_search_smpp_tcp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_packet_struct* packet = &flow->packet; // min SMPP packet length = 16 bytes if (packet->payload_packet_len < 16) { - NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); - NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); - return; + NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); + NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); + return; } // get PDU length - uint32_t pdu_l = ntohl(get_u_int32_t(packet->payload, 0)); + u_int32_t pdu_l = ntohl(get_u_int32_t(packet->payload, 0)); NDPI_LOG(NDPI_PROTOCOL_SMPP, - ndpi_struct, - NDPI_LOG_DEBUG, - "calculated PDU Length: %d, received PDU Length: %d\n", - pdu_l, packet->payload_packet_len); + ndpi_struct, + NDPI_LOG_DEBUG, + "calculated PDU Length: %d, received PDU Length: %d\n", + pdu_l, packet->payload_packet_len); // if PDU size was invalid, try the following TCP segments, 3 attempts max if(flow->packet_counter > 3) { - NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); - NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); - return; + NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); + NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); + return; } // verify PDU length if(pdu_l != packet->payload_packet_len) { - // check if multiple PDUs included - uint32_t total_pdu_l = pdu_l; - uint32_t tmp_pdu_l = 0; - uint16_t pdu_c = 1; - // loop PDUs (check if lengths are valid) - while(total_pdu_l < packet->payload_packet_len) { - // get next PDU length - tmp_pdu_l = ntohl(get_u_int32_t(packet->payload, total_pdu_l)); - // if zero, return, will try the next TCP segment - if(tmp_pdu_l == 0) return; - // inc total PDU length - total_pdu_l += ntohl(get_u_int32_t(packet->payload, total_pdu_l)); - // inc total PDU count - ++pdu_c; - } + // check if multiple PDUs included + u_int32_t total_pdu_l = pdu_l; + u_int32_t tmp_pdu_l = 0; + u_int16_t pdu_c = 1; + // loop PDUs (check if lengths are valid) + while(total_pdu_l < packet->payload_packet_len) { + // get next PDU length + tmp_pdu_l = ntohl(get_u_int32_t(packet->payload, total_pdu_l)); + // if zero, return, will try the next TCP segment + if(tmp_pdu_l == 0) return; + // inc total PDU length + total_pdu_l += ntohl(get_u_int32_t(packet->payload, total_pdu_l)); + // inc total PDU count + ++pdu_c; + } - NDPI_LOG(NDPI_PROTOCOL_SMPP, - ndpi_struct, - NDPI_LOG_DEBUG, - "multiple PDUs included, calculated total PDU Length: %d, PDU count: %d, TCP payload length: %d\n", - total_pdu_l, pdu_c, packet->payload_packet_len); - - // verify multi PDU total length - if(total_pdu_l != packet->payload_packet_len){ - // return, will try the next TCP segment - return; - } + NDPI_LOG(NDPI_PROTOCOL_SMPP, + ndpi_struct, + NDPI_LOG_DEBUG, + "multiple PDUs included, calculated total PDU Length: %d, PDU count: %d, TCP payload length: %d\n", + total_pdu_l, pdu_c, packet->payload_packet_len); + + // verify multi PDU total length + if(total_pdu_l != packet->payload_packet_len){ + // return, will try the next TCP segment + return; + } } // *** check PDU type *** - uint32_t pdu_type = ntohl(get_u_int32_t(packet->payload, 4)); + u_int32_t pdu_type = ntohl(get_u_int32_t(packet->payload, 4)); // first byte of PDU type is either 0x00 of 0x80 if(!(packet->payload[4] == 0x00 || packet->payload[4] == 0x80)) { - NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); - NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); - return; + NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); + NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); + return; } // remove 0x80, get request type pdu - uint32_t pdu_req = pdu_type & 0x00FFFFFF; + u_int32_t pdu_req = pdu_type & 0x00FFFFFF; // list of known PDU types if((pdu_req >= 0x00000000 && pdu_req <= 0x00000009) || (pdu_req == 0x0000000B || pdu_req == 0x00000015 || pdu_req == 0x00000021 || pdu_req == 0x00000102 || pdu_req == 0x00000103)){ - NDPI_LOG(NDPI_PROTOCOL_SMPP, - ndpi_struct, - NDPI_LOG_DEBUG, - "PDU type: %x, Request PDU type = %x\n", - pdu_type, pdu_req); - - // fresult flag - char extra_passed = 1; - // check PDU type specifics - switch(pdu_type){ - // GENERIC_NACK - case 0x80000000: - // body lengh must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - // BIND_RECEIVER - // BIND_TRANSMITTER - // BIND_TRANSCEIVER - case 0x00000001: - case 0x00000002: - case 0x00000009: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body lengh = 10 bytes (+16 in header) - if(pdu_l < 26) extra_passed = 0; - break; - - // BIND_RECEIVER_RESP - // BIND_TRANSMITTER_RESP - // BIND_TRANSCEIVER_RESP - case 0x80000001: - case 0x80000002: - case 0x80000009: - // min body length = 2 bytes (+16 in header) - if(pdu_l < 18) extra_passed = 0; - break; - - // OUTBIND - case 0x0000000B: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 4 bytes (+16 in header) - if(pdu_l < 20) extra_passed = 0; - break; - - // UNBIND - case 0x00000006: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // body lengh must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - // UNBIND_RESP - case 0x80000006: - // body lengh must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - - // SUBMIT_SM - case 0x00000004: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 17 bytes (+16 in header) - if(pdu_l < 33) extra_passed = 0; - break; + NDPI_LOG(NDPI_PROTOCOL_SMPP, + ndpi_struct, + NDPI_LOG_DEBUG, + "PDU type: %x, Request PDU type = %x\n", + pdu_type, pdu_req); + + // fresult flag + char extra_passed = 1; + // check PDU type specifics + switch(pdu_type){ + // GENERIC_NACK + case 0x80000000: + // body lengh must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + // BIND_RECEIVER + // BIND_TRANSMITTER + // BIND_TRANSCEIVER + case 0x00000001: + case 0x00000002: + case 0x00000009: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body lengh = 10 bytes (+16 in header) + if(pdu_l < 26) extra_passed = 0; + break; + + // BIND_RECEIVER_RESP + // BIND_TRANSMITTER_RESP + // BIND_TRANSCEIVER_RESP + case 0x80000001: + case 0x80000002: + case 0x80000009: + // min body length = 2 bytes (+16 in header) + if(pdu_l < 18) extra_passed = 0; + break; + + // OUTBIND + case 0x0000000B: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 4 bytes (+16 in header) + if(pdu_l < 20) extra_passed = 0; + break; + + // UNBIND + case 0x00000006: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // body lengh must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + // UNBIND_RESP + case 0x80000006: + // body lengh must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + + // SUBMIT_SM + case 0x00000004: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 17 bytes (+16 in header) + if(pdu_l < 33) extra_passed = 0; + break; - // SUBMIT_SM_RESP - case 0x80000004: - // - if status != 0, body length is 2 bytes min - // - if status > 0, body lenth must be zero - if(get_u_int32_t(packet->payload, 8) != 0){ - if(pdu_l > 16) extra_passed = 0; - - }else if(pdu_l < 18) extra_passed = 0; - break; - - // SUBMIT_MULTI - case 0x00000021: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 17 bytes (+16 in header) - if(pdu_l < 33) extra_passed = 0; - break; - - // SUBMIT_MULTI_RESP - case 0x80000021: - // min body length = 10 bytes (+16 in header) - if(pdu_l < 26) extra_passed = 0; - break; - - // DELIVER_SM - case 0x00000005: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 17 bytes (+16 in header) - if(pdu_l < 33) extra_passed = 0; - break; - - // DELIVER_SM_RESP - case 0x80000005: - // min body length = 1 byte (+16 in header) - if(pdu_l < 17) extra_passed = 0; - break; + // SUBMIT_SM_RESP + case 0x80000004: + // - if status != 0, body length is 2 bytes min + // - if status > 0, body lenth must be zero + if(get_u_int32_t(packet->payload, 8) != 0){ + if(pdu_l > 16) extra_passed = 0; + + }else if(pdu_l < 18) extra_passed = 0; + break; + + // SUBMIT_MULTI + case 0x00000021: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 17 bytes (+16 in header) + if(pdu_l < 33) extra_passed = 0; + break; + + // SUBMIT_MULTI_RESP + case 0x80000021: + // min body length = 10 bytes (+16 in header) + if(pdu_l < 26) extra_passed = 0; + break; + + // DELIVER_SM + case 0x00000005: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 17 bytes (+16 in header) + if(pdu_l < 33) extra_passed = 0; + break; + + // DELIVER_SM_RESP + case 0x80000005: + // min body length = 1 byte (+16 in header) + if(pdu_l < 17) extra_passed = 0; + break; - // DATA_SM - case 0x00000103: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 10 bytes (+16 in header) - if(pdu_l < 26) extra_passed = 0; - break; - - // DATA_SM_RESP - case 0x80000103: - // min body length = 2 bytes (+16 in header) - if(pdu_l < 18) extra_passed = 0; - break; - - // QUERY_SM - case 0x00000003: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 4 bytes (+16 in header) - if(pdu_l < 20) extra_passed = 0; - break; - - // QUERY_SM_RESP - case 0x80000003: - // min body length = 5 bytes (+16 in header) - if(pdu_l < 21) extra_passed = 0; - break; - - // CANCEL_SM - case 0x00000008: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 8 bytes (+16 in header) - if(pdu_l < 24) extra_passed = 0; - break; - - // CANCEL_SM_RESP - case 0x80000008: - // body lenth must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - // REPLACE_SM - case 0x00000007: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 9 bytes (+16 in header) - if(pdu_l < 25) extra_passed = 0; - break; - - // REPLACE_SM_RESP - case 0x80000007: - // body lenth must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - // ENQUIRE_LINK - case 0x00000015: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // body lengh must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - // ENQUIRE_LINK_RESP - case 0x80000015: - // body lengh must be zero - if(pdu_l > 16) extra_passed = 0; - break; - - // ALERT_NOTIFICATION - case 0x00000102: - // status field must be NULL - if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; - // min body length = 6 bytes (+16 in header) - if(pdu_l < 22) extra_passed = 0; - break; - - default: break; - } - - // if extra checks passed, set as identified - if(extra_passed) { - NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP identified...\n"); - ndpi_int_smpp_add_connection(ndpi_struct, flow); - return; - } + // DATA_SM + case 0x00000103: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 10 bytes (+16 in header) + if(pdu_l < 26) extra_passed = 0; + break; + + // DATA_SM_RESP + case 0x80000103: + // min body length = 2 bytes (+16 in header) + if(pdu_l < 18) extra_passed = 0; + break; + + // QUERY_SM + case 0x00000003: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 4 bytes (+16 in header) + if(pdu_l < 20) extra_passed = 0; + break; + + // QUERY_SM_RESP + case 0x80000003: + // min body length = 5 bytes (+16 in header) + if(pdu_l < 21) extra_passed = 0; + break; + + // CANCEL_SM + case 0x00000008: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 8 bytes (+16 in header) + if(pdu_l < 24) extra_passed = 0; + break; + + // CANCEL_SM_RESP + case 0x80000008: + // body lenth must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + // REPLACE_SM + case 0x00000007: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 9 bytes (+16 in header) + if(pdu_l < 25) extra_passed = 0; + break; + + // REPLACE_SM_RESP + case 0x80000007: + // body lenth must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + // ENQUIRE_LINK + case 0x00000015: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // body lengh must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + // ENQUIRE_LINK_RESP + case 0x80000015: + // body lengh must be zero + if(pdu_l > 16) extra_passed = 0; + break; + + // ALERT_NOTIFICATION + case 0x00000102: + // status field must be NULL + if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; + // min body length = 6 bytes (+16 in header) + if(pdu_l < 22) extra_passed = 0; + break; + + default: break; + } + + // if extra checks passed, set as identified + if(extra_passed) { + NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP identified...\n"); + ndpi_int_smpp_add_connection(ndpi_struct, flow); + return; + } } // exclude |