|
Kannel: Open Source WAP and SMS gateway
svn-r5336
|
#include <errno.h>#include <ctype.h>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include <sys/time.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <sys/param.h>#include <signal.h>#include <fcntl.h>#include <sys/stat.h>#include "gwlib/gwlib.h"#include "wap/wsp_pdu.h"Go to the source code of this file.
Macros | |
| #define | MAX_SEND (0) |
| #define | GET_WTP_PDU_TYPE(hdr) ((hdr[0] >> 3) & 0x0f) |
| #define | WTP_PDU_INVOKE 1 |
| #define | WTP_PDU_RESULT 2 |
| #define | WTP_PDU_ACK 3 |
| #define | WTP_PDU_ABORT 4 |
| #define | WTP_PDU_SEGM_INVOKE 5 |
| #define | WTP_PDU_SEGM_RESULT 6 |
| #define | WTP_PDU_NACK 7 |
| #define | WSP_PDU_CONNECT 1 |
| #define | WSP_PDU_REPLY 4 |
| #define | WSP_PDU_DISCONNECT 5 |
| #define | WSP_PDU_GET 0x40 |
| #define | WSP_PDU_POST 0x60 |
| #define | TXN_MODE_CONNECTION_LESS 0 |
| #define | TXN_MODE_CONNECTION_ORIENTED 1 |
| #define | SAR_SEGM_SIZE 1200 |
| #define | SAR_GROUP_LEN 4 |
| #define | SAR_MAX_RETRIES 3 |
| #define | WAP_MSG_RECEIVE_TIMEOUT 10 |
| #define | SET_GTR(hdr) hdr[0] |= 0x04 |
| #define | SET_TID(hdr, tid) |
| #define | GET_TID(hdr) (((hdr[1] & 0x7f) << 8) + hdr[2]) |
| #define | CONSTRUCT_EXPECTED_REPLY_HDR(dest, template, tid) |
| #define | min(a, b) (a < b ? a : b) |
Functions | |
| static int | get_wtp_pdu_type (Octstr *hdr) |
| static void | set_tid (Octstr *hdr, int tid) |
| static void | set_tid_new (Octstr *hdr) |
| static void | print_msg (const char *trace, unsigned char *msg, int msg_len) |
| static void | print_data (const char *trace, unsigned char *msg, int msg_len) |
| static char * | choose_message (char **urls, int num_urls) |
| static unsigned short | next_tid (unsigned short old_tid) |
| static int | StoreVarInt (unsigned char *buf, unsigned long varInt) |
| static int | ReadVarIntLen (const unsigned char *buf) |
| static int | ReadVarIntVal (const unsigned char *buf) |
| static int | wap_msg_send (int fd, unsigned char *wtp_hdr, int wtp_hdr_len, unsigned short tid, int tid_new, unsigned char *wsp_hdr, int wsp_hdr_len, unsigned char *data, int data_len) |
| static int | wap_msg_recv (int fd, const unsigned char *hdr, int hdr_len, unsigned short tid, unsigned char *data, int data_len, int timeout, int udp_flags) |
| static int | get_next_transaction (void) |
| int | send_post (int fd, unsigned short tid, int tid_new, char *url) |
| static void | client_session (void *arg) |
| static void | help (void) |
| int | main (int argc, char **argv) |
Variables | |
| static char | usage [] |
| char ** | urls |
| int | num_urls |
| Octstr * | hostname = NULL |
| Octstr * | gateway_addr = NULL |
| double | interval = 1.0 |
| unsigned short | port = 0 |
| int | max_send = 1 |
| unsigned short | tid_addition = 1 |
| Mutex * | mutex |
| int | threads = 1 |
| int | num_sent = 0 |
| time_t | start_time |
| time_t | end_time |
| double | totaltime = 0 |
| double | besttime = 1000000L |
| double | worsttime = 0 |
| int | brief |
| int | verbose = 0 |
| int | nofailexit = 0 |
| int | test_separation = 0 |
| char * | infile |
| char * | outfile |
| const char * | content_type |
| struct sockaddr_in | src_addr |
| int | transaction_mode |
| int | packet_loss |
| Octstr * | useragent |
| unsigned char | WSP_Connect [] |
| unsigned char | WSP_ConnectReply [] = {0x16, 0x80, 0x00, 0x02 } |
| unsigned char | WSP_Get [] = {0x40} |
| unsigned char | WSP_Reply [] = {0x16, 0x80, 0x00, 0x04, 0x20 } |
| unsigned char | WSP_Disconnect [] = {0x05} |
| unsigned char | WSP_Post [] = { 0x60 } |
| unsigned char | WSP_Concat [] = {0x00, 0x03, 0x18, 0x00, 0x00, 0x05, 0x0E, 0x00, 0x00, 0x00, 0x05 } |
| unsigned char | WTP_Ack [] = {0x18, 0x00, 0x00 } |
| unsigned char | WTP_TidVe [] = {0x1C, 0x00, 0x00 } |
| unsigned char | WTP_Abort [] = {0x20, 0x00, 0x00, 0x00 } |
| unsigned char | WTP_Invoke_Cl0 [] = { 0x0a, 0x00, 0x00, 0x10 } |
| unsigned char | WTP_Invoke_Cl2 [] = { 0x0a, 0x00, 0x00, 0x12 } |
| unsigned char | WTP_Invoke_Cl2MaxGrp [] |
| unsigned char | WTP_Result [] = {0x10, 0x80, 0x00 } |
| unsigned char | WTP_Segm_Result [] = {0x30, 0x80, 0x00 } |
| unsigned char | WTP_Segm_Ack [] = {0x98, 0x00, 0x00, 0x19, 0x00 } |
| unsigned char | WTP_Nack [] = { 0x38, 0x00, 0x00, 0x00 } |
| unsigned char | WTP_Segm_Invoke [] = { 0x28, 0x00, 0x00, 0x00 } |
| #define CONSTRUCT_EXPECTED_REPLY_HDR | ( | dest, | |
| template, | |||
| tid | |||
| ) |
Definition at line 301 of file fakewap.c.
Referenced by client_session(), and send_post().
| #define GET_TID | ( | hdr | ) | (((hdr[1] & 0x7f) << 8) + hdr[2]) |
Definition at line 300 of file fakewap.c.
Referenced by wap_msg_recv().
| #define GET_WTP_PDU_TYPE | ( | hdr | ) | ((hdr[0] >> 3) & 0x0f) |
Definition at line 198 of file fakewap.c.
Referenced by client_session(), and wap_msg_recv().
| #define MAX_SEND (0) |
Definition at line 132 of file fakewap.c.
Referenced by client_session(), and get_next_transaction().
| #define min | ( | a, | |
| b | |||
| ) | (a < b ? a : b) |
Definition at line 326 of file fakewap.c.
Referenced by wap_msg_recv().
| #define SAR_GROUP_LEN 4 |
Definition at line 222 of file fakewap.c.
Referenced by send_post(), and wtp_pack_sar_result().
| #define SAR_MAX_RETRIES 3 |
Definition at line 223 of file fakewap.c.
Referenced by send_post().
| #define SAR_SEGM_SIZE 1200 |
Definition at line 221 of file fakewap.c.
Referenced by begin_sar_result(), send_post(), and wtp_pack_sar_result().
| #define SET_TID | ( | hdr, | |
| tid | |||
| ) |
| #define TXN_MODE_CONNECTION_LESS 0 |
Definition at line 218 of file fakewap.c.
Referenced by client_session(), main(), and send_post().
| #define TXN_MODE_CONNECTION_ORIENTED 1 |
Definition at line 219 of file fakewap.c.
Referenced by client_session(), main(), send_post(), and wap_msg_send().
| #define WAP_MSG_RECEIVE_TIMEOUT 10 |
Definition at line 224 of file fakewap.c.
Referenced by client_session(), and send_post().
| #define WSP_PDU_CONNECT 1 |
Definition at line 212 of file fakewap.c.
Referenced by wap_msg_send().
| #define WSP_PDU_DISCONNECT 5 |
Definition at line 214 of file fakewap.c.
Referenced by wap_msg_send().
| #define WSP_PDU_GET 0x40 |
Definition at line 215 of file fakewap.c.
Referenced by wap_msg_send().
| #define WSP_PDU_POST 0x60 |
Definition at line 216 of file fakewap.c.
Referenced by wap_msg_send().
| #define WTP_PDU_ABORT 4 |
Definition at line 207 of file fakewap.c.
Referenced by wap_msg_recv(), and wap_msg_send().
| #define WTP_PDU_ACK 3 |
Definition at line 206 of file fakewap.c.
Referenced by wap_msg_recv(), and wap_msg_send().
| #define WTP_PDU_INVOKE 1 |
Definition at line 204 of file fakewap.c.
Referenced by send_post(), and wap_msg_send().
| #define WTP_PDU_NACK 7 |
Definition at line 210 of file fakewap.c.
Referenced by wap_msg_send().
| #define WTP_PDU_RESULT 2 |
Definition at line 205 of file fakewap.c.
Referenced by client_session(), and wap_msg_recv().
| #define WTP_PDU_SEGM_INVOKE 5 |
Definition at line 208 of file fakewap.c.
Referenced by send_post(), and wap_msg_send().
| #define WTP_PDU_SEGM_RESULT 6 |
Definition at line 209 of file fakewap.c.
Referenced by wap_msg_recv().
|
static |
|
static |
Definition at line 875 of file fakewap.c.
References besttime, brief, choose_message(), CONSTRUCT_EXPECTED_REPLY_HDR, debug(), end_time, error(), get_next_transaction(), GET_WTP_PDU_TYPE, infile, info(), interval, MAX_SEND, max_send, mutex, mutex_lock, mutex_unlock, next_tid(), num_urls, octstr_append_data(), octstr_create, octstr_get_char(), octstr_get_cstr, octstr_len(), outfile, panic, ReadVarIntLen(), ReadVarIntVal(), send_post(), src_addr, StoreVarInt(), totaltime, transaction_mode, TXN_MODE_CONNECTION_LESS, TXN_MODE_CONNECTION_ORIENTED, wsp_pdu::type, wsp_pdu::u, udp_client_socket(), url, urls, useragent, WAP_MSG_RECEIVE_TIMEOUT, wap_msg_recv(), wap_msg_send(), warning(), worsttime, WSP_Connect, WSP_ConnectReply, WSP_Disconnect, WSP_Get, wsp_pdu_unpack(), WTP_Abort, WTP_Ack, WTP_Invoke_Cl0, WTP_Invoke_Cl2, WTP_Nack, WTP_PDU_RESULT, WTP_Result, and WTP_Segm_Ack.
Referenced by main().
|
static |
Definition at line 648 of file fakewap.c.
References MAX_SEND, max_send, mutex, mutex_lock, mutex_unlock, and num_sent.
Referenced by client_session().
|
static |
Definition at line 199 of file fakewap.c.
References octstr_get_char().
Referenced by wap_msg_send().
|
static |
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 1196 of file fakewap.c.
References besttime, brief, client_session(), content_type, end_time, error(), gateway_addr, getopt(), GW_INFO, gwlib_init(), gwlib_shutdown(), gwthread_create, gwthread_join_every(), help(), hostname, infile, info(), interval, log_set_output_level(), max_send, mutex, mutex_create, mutex_destroy(), nofailexit, num_sent, num_urls, octstr_append_data(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_len(), optarg, optind, outfile, packet_loss, panic, src_addr, start_time, test_separation, threads, tid_addition, totaltime, transaction_mode, TXN_MODE_CONNECTION_LESS, TXN_MODE_CONNECTION_ORIENTED, udp_create_address(), urls, usage, useragent, verbose, worsttime, and WTP_Invoke_Cl2.
|
static |
|
static |
Definition at line 348 of file fakewap.c.
References msg, mutex, mutex_lock, mutex_unlock, and verbose.
Referenced by wap_msg_recv().
|
static |
Definition at line 334 of file fakewap.c.
References msg, mutex, mutex_lock, mutex_unlock, and verbose.
Referenced by wap_msg_recv().
|
static |
Definition at line 408 of file fakewap.c.
Referenced by client_session().
|
static |
Definition at line 419 of file fakewap.c.
Referenced by client_session().
| int send_post | ( | int | fd, |
| unsigned short | tid, | ||
| int | tid_new, | ||
| char * | url | ||
| ) |
Definition at line 657 of file fakewap.c.
References CONSTRUCT_EXPECTED_REPLY_HDR, content_type, debug(), error(), infile, octstr_append_data(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_len(), panic, SAR_GROUP_LEN, SAR_MAX_RETRIES, SAR_SEGM_SIZE, StoreVarInt(), transaction_mode, TXN_MODE_CONNECTION_LESS, TXN_MODE_CONNECTION_ORIENTED, url, useragent, WAP_MSG_RECEIVE_TIMEOUT, wap_msg_recv(), wap_msg_send(), warning(), WSP_Post, WTP_Ack, WTP_Invoke_Cl2MaxGrp, WTP_PDU_INVOKE, WTP_PDU_SEGM_INVOKE, WTP_Result, WTP_Segm_Ack, and WTP_Segm_Invoke.
Referenced by client_session().
|
static |
Definition at line 306 of file fakewap.c.
References octstr_get_char(), and octstr_set_char().
Referenced by wap_msg_send().
|
static |
Definition at line 316 of file fakewap.c.
References octstr_get_char(), and octstr_set_char().
Referenced by wap_msg_send().
|
static |
|
static |
Definition at line 540 of file fakewap.c.
References debug(), error(), GET_TID, GET_WTP_PDU_TYPE, gw_rand(), info(), min, msg, nofailexit, octstr_destroy(), octstr_get_many_chars(), octstr_len(), packet_loss, print_data(), print_msg(), read_available(), udp_recvfrom_flags(), wap_msg_send(), WTP_PDU_ABORT, WTP_PDU_ACK, WTP_PDU_RESULT, WTP_PDU_SEGM_RESULT, and WTP_TidVe.
Referenced by client_session(), and send_post().
|
static |
Definition at line 436 of file fakewap.c.
References brief, debug(), error(), gateway_addr, get_wtp_pdu_type(), octstr_append_data(), octstr_create, octstr_destroy(), octstr_dump, octstr_get_char(), octstr_set_char(), set_tid(), set_tid_new(), transaction_mode, TXN_MODE_CONNECTION_ORIENTED, udp_sendto(), verbose, WSP_PDU_CONNECT, WSP_PDU_DISCONNECT, WSP_PDU_GET, WSP_PDU_POST, WTP_PDU_ABORT, WTP_PDU_ACK, WTP_PDU_INVOKE, WTP_PDU_NACK, and WTP_PDU_SEGM_INVOKE.
Referenced by client_session(), send_post(), and wap_msg_recv().
| double besttime = 1000000L |
Definition at line 242 of file fakewap.c.
Referenced by client_session(), and main().
| int brief |
Definition at line 243 of file fakewap.c.
Referenced by client_session(), main(), and wap_msg_send().
| const char* content_type |
Definition at line 249 of file fakewap.c.
Referenced by convert_charset(), generic_send_sms(), get_start_param(), http_accept_request(), httpd_serve(), main(), send_post(), and wsp_pack_separate_content_type().
| time_t end_time |
Definition at line 241 of file fakewap.c.
Referenced by at2_wait_line(), at2_wait_modem_command(), client_session(), and main().
| Octstr* gateway_addr = NULL |
Definition at line 233 of file fakewap.c.
Referenced by main(), and wap_msg_send().
| Octstr* hostname = NULL |
Definition at line 232 of file fakewap.c.
Referenced by cimd_open(), http_use_proxy(), main(), ois_open(), tcpip_connect_nb_to_server(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server(), and tcpip_connect_to_server_with_port().
| char* infile |
Definition at line 247 of file fakewap.c.
Referenced by client_session(), get_mbi(), main(), send_post(), and skip_mbi().
| double interval = 1.0 |
Definition at line 234 of file fakewap.c.
Referenced by client_session(), gen_data(), gw_timer_elapsed_start(), gw_timer_elapsed_start_cb(), gw_timer_start(), gwtimer_start(), load_add_interval(), main(), and main_loop().
| int max_send = 1 |
Definition at line 236 of file fakewap.c.
Referenced by client_session(), get_next_transaction(), and main().
| Mutex* mutex |
Definition at line 238 of file fakewap.c.
Referenced by client_session(), get_next_transaction(), main(), mutex_create_real(), mutex_destroy(), mutex_init_static_real(), mutex_lock_real(), mutex_trylock_real(), mutex_unlock_real(), print_data(), and print_msg().
| int nofailexit = 0 |
Definition at line 245 of file fakewap.c.
Referenced by main(), and wap_msg_recv().
| int num_sent = 0 |
Definition at line 240 of file fakewap.c.
Referenced by get_next_transaction(), and main().
| int num_urls |
Definition at line 230 of file fakewap.c.
Referenced by choose_message(), client_session(), and main().
| char* outfile |
Definition at line 248 of file fakewap.c.
Referenced by client_session(), main(), and print_extparms().
| int packet_loss |
Definition at line 252 of file fakewap.c.
Referenced by main(), and wap_msg_recv().
| struct sockaddr_in src_addr |
Definition at line 250 of file fakewap.c.
Referenced by client_session(), and main().
| unsigned short tid_addition = 1 |
Definition at line 237 of file fakewap.c.
Referenced by main(), and next_tid().
| double totaltime = 0 |
Definition at line 242 of file fakewap.c.
Referenced by client_session(), and main().
| int transaction_mode |
Definition at line 251 of file fakewap.c.
Referenced by client_session(), main(), send_post(), and wap_msg_send().
| char** urls |
Definition at line 229 of file fakewap.c.
Referenced by choose_message(), client_session(), and main().
| Octstr* useragent |
Definition at line 253 of file fakewap.c.
Referenced by client_session(), main(), and send_post().
| int verbose = 0 |
Definition at line 244 of file fakewap.c.
Referenced by main(), print_data(), print_msg(), and wap_msg_send().
| double worsttime = 0 |
Definition at line 242 of file fakewap.c.
Referenced by client_session(), and main().
| unsigned char WSP_Concat[] = {0x00, 0x03, 0x18, 0x00, 0x00, 0x05, 0x0E, 0x00, 0x00, 0x00, 0x05 } |
| unsigned char WSP_Connect[] |
Definition at line 260 of file fakewap.c.
Referenced by client_session().
| unsigned char WSP_ConnectReply[] = {0x16, 0x80, 0x00, 0x02 } |
Definition at line 271 of file fakewap.c.
Referenced by client_session().
| unsigned char WSP_Disconnect[] = {0x05} |
Definition at line 276 of file fakewap.c.
Referenced by client_session().
| unsigned char WSP_Get[] = {0x40} |
Definition at line 272 of file fakewap.c.
Referenced by client_session().
| unsigned char WSP_Post[] = { 0x60 } |
Definition at line 277 of file fakewap.c.
Referenced by send_post().
| unsigned char WSP_Reply[] = {0x16, 0x80, 0x00, 0x04, 0x20 } |
| unsigned char WTP_Abort[] = {0x20, 0x00, 0x00, 0x00 } |
Definition at line 282 of file fakewap.c.
Referenced by client_session().
| unsigned char WTP_Ack[] = {0x18, 0x00, 0x00 } |
Definition at line 280 of file fakewap.c.
Referenced by client_session(), and send_post().
| unsigned char WTP_Invoke_Cl0[] = { 0x0a, 0x00, 0x00, 0x10 } |
Definition at line 283 of file fakewap.c.
Referenced by client_session().
| unsigned char WTP_Invoke_Cl2[] = { 0x0a, 0x00, 0x00, 0x12 } |
Definition at line 284 of file fakewap.c.
Referenced by client_session(), and main().
| unsigned char WTP_Invoke_Cl2MaxGrp[] |
Definition at line 285 of file fakewap.c.
Referenced by send_post().
| unsigned char WTP_Nack[] = { 0x38, 0x00, 0x00, 0x00 } |
Definition at line 290 of file fakewap.c.
Referenced by client_session().
| unsigned char WTP_Result[] = {0x10, 0x80, 0x00 } |
Definition at line 287 of file fakewap.c.
Referenced by client_session(), and send_post().
| unsigned char WTP_Segm_Ack[] = {0x98, 0x00, 0x00, 0x19, 0x00 } |
Definition at line 289 of file fakewap.c.
Referenced by client_session(), and send_post().
| unsigned char WTP_Segm_Invoke[] = { 0x28, 0x00, 0x00, 0x00 } |
Definition at line 291 of file fakewap.c.
Referenced by send_post().
| unsigned char WTP_TidVe[] = {0x1C, 0x00, 0x00 } |
Definition at line 281 of file fakewap.c.
Referenced by wap_msg_recv().