Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wtp_pack.h File Reference
#include "gwlib/gwlib.h"
#include "wap_events.h"
#include "wtp_init.h"
#include "wtp_resp.h"
#include "wtp.h"
#include "wap.h"

Go to the source code of this file.

Functions

WAPEventwtp_pack_invoke (WTPInitMachine *init_machine, WAPEvent *event)
 
WAPEventwtp_pack_result (WTPRespMachine *resp_machine, WAPEvent *event)
 
WAPEventwtp_pack_sar_result (WTPRespMachine *resp_machine, int psn)
 
WAPEventwtp_pack_abort (long abort_type, long abort_reason, long tid, WAPAddrTuple *address)
 
WAPEventwtp_pack_ack (long ack_type, int rid_flag, long tid, WAPAddrTuple *address)
 
WAPEventwtp_pack_sar_ack (long ack_type, long tid, WAPAddrTuple *address, int psn)
 
void wtp_pack_set_rid (WAPEvent *dgram, long rid)
 

Function Documentation

WAPEvent* wtp_pack_abort ( long  abort_type,
long  abort_reason,
long  tid,
WAPAddrTuple address 
)

Definition at line 223 of file wtp_pack.c.

References send_tid(), WAPEvent::u, wtp_pdu::u, wap_addr_tuple_duplicate(), wap_event_create, wtp_pdu_create(), wtp_pdu_destroy(), and wtp_pdu_pack().

Referenced by handle_wrong_version(), init_machine_find_or_create(), and send_abort().

225 {
226  WAPEvent *dgram;
227  WTP_PDU *pdu;
228 
229  pdu = wtp_pdu_create(Abort);
230  pdu->u.Abort.con = 0;
231  pdu->u.Abort.abort_type = abort_type;
232  pdu->u.Abort.tid = send_tid(tid);
233  pdu->u.Abort.abort_reason = abort_reason;
234 
235  dgram = wap_event_create(T_DUnitdata_Req);
236  dgram->u.T_DUnitdata_Req.addr_tuple = wap_addr_tuple_duplicate(address);
237  dgram->u.T_DUnitdata_Req.user_data = wtp_pdu_pack(pdu);
238  wtp_pdu_destroy(pdu);
239 
240  return dgram;
241 }
WTP_PDU * wtp_pdu_create(int type)
Definition: wtp_pdu.c:67
long tid
Definition: wtp.h:190
static unsigned short send_tid(unsigned short tid)
Definition: wtp_pack.c:291
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
union wtp_pdu::@107 u
#define wap_event_create(type)
Definition: wap_events.h:107
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
union WAPEvent::@87 u
WAPEvent* wtp_pack_ack ( long  ack_type,
int  rid_flag,
long  tid,
WAPAddrTuple address 
)

Definition at line 243 of file wtp_pack.c.

References send_tid(), WAPEvent::u, wtp_pdu::u, wap_addr_tuple_duplicate(), wap_event_create, wtp_pdu_create(), wtp_pdu_destroy(), and wtp_pdu_pack().

Referenced by send_ack().

245 {
246  WAPEvent *dgram = NULL;
247  WTP_PDU *pdu;
248 
249  pdu = wtp_pdu_create(Ack);
250  pdu->u.Ack.con = 0;
251  pdu->u.Ack.tidverify = ack_type;
252  pdu->u.Ack.rid = rid_flag;
253  pdu->u.Ack.tid = send_tid(tid);
254 
255  dgram = wap_event_create(T_DUnitdata_Req);
256  dgram->u.T_DUnitdata_Req.addr_tuple = wap_addr_tuple_duplicate(address);
257  dgram->u.T_DUnitdata_Req.user_data = wtp_pdu_pack(pdu);
258  wtp_pdu_destroy(pdu);
259 
260  return dgram;
261 }
WTP_PDU * wtp_pdu_create(int type)
Definition: wtp_pdu.c:67
long tid
Definition: wtp.h:190
static unsigned short send_tid(unsigned short tid)
Definition: wtp_pack.c:291
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
union wtp_pdu::@107 u
#define wap_event_create(type)
Definition: wap_events.h:107
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
union WAPEvent::@87 u
WAPEvent* wtp_pack_invoke ( WTPInitMachine init_machine,
WAPEvent event 
)

Definition at line 115 of file wtp_pack.c.

References gw_assert(), octstr_duplicate, send_tid(), WAPEvent::type, WAPEvent::u, wtp_pdu::u, wap_addr_tuple_duplicate(), wap_event_create, wtp_pdu_create(), wtp_pdu_destroy(), and wtp_pdu_pack().

116 {
117  WAPEvent *dgram = NULL;
118  WTP_PDU *pdu = NULL;
119 
120  gw_assert(event->type == TR_Invoke_Req);
121  pdu = wtp_pdu_create(Invoke);
122  pdu->u.Invoke.con = 0;
123  pdu->u.Invoke.gtr = 1;
124  pdu->u.Invoke.ttr = 1;
125  pdu->u.Invoke.rid = 0;
126  pdu->u.Invoke.version = 0;
127  pdu->u.Invoke.tid = send_tid(machine->tid);
128  pdu->u.Invoke.tidnew = machine->tidnew;
129  pdu->u.Invoke.user_data =
130  octstr_duplicate(event->u.TR_Invoke_Req.user_data);
131  pdu->u.Invoke.class = event->u.TR_Invoke_Req.tcl;
132  pdu->u.Invoke.uack = event->u.TR_Invoke_Req.up_flag;
133 
134  dgram = wap_event_create(T_DUnitdata_Req);
135  dgram->u.T_DUnitdata_Req.addr_tuple =
136  wap_addr_tuple_duplicate(machine->addr_tuple);
137  dgram->u.T_DUnitdata_Req.user_data = wtp_pdu_pack(pdu);
138  wtp_pdu_destroy(pdu);
139 
140  return dgram;
141 }
WTP_PDU * wtp_pdu_create(int type)
Definition: wtp_pdu.c:67
static unsigned short send_tid(unsigned short tid)
Definition: wtp_pack.c:291
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
union wtp_pdu::@107 u
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define wap_event_create(type)
Definition: wap_events.h:107
gw_assert(wtls_machine->packet_to_send!=NULL)
WAPEventName type
Definition: wap_events.h:88
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
union WAPEvent::@87 u
WAPEvent* wtp_pack_result ( WTPRespMachine resp_machine,
WAPEvent event 
)

Definition at line 143 of file wtp_pack.c.

References gw_assert(), octstr_duplicate, send_tid(), WAPEvent::type, WAPEvent::u, wtp_pdu::u, wap_addr_tuple_duplicate(), wap_event_create, wtp_pdu_create(), wtp_pdu_destroy(), and wtp_pdu_pack().

144 {
145  WAPEvent *dgram = NULL;
146  WTP_PDU *pdu = NULL;
147 
148  gw_assert(event->type == TR_Result_Req);
149  pdu = wtp_pdu_create(Result);
150  pdu->u.Result.con = 0;
151  pdu->u.Result.gtr = 1;
152  pdu->u.Result.ttr = 1;
153  pdu->u.Result.rid = 0;
154  pdu->u.Result.tid = send_tid(machine->tid);
155  pdu->u.Result.user_data =
156  octstr_duplicate(event->u.TR_Result_Req.user_data);
157 
158  dgram = wap_event_create(T_DUnitdata_Req);
159  dgram->u.T_DUnitdata_Req.addr_tuple =
160  wap_addr_tuple_duplicate(machine->addr_tuple);
161  dgram->u.T_DUnitdata_Req.user_data = wtp_pdu_pack(pdu);
162  wtp_pdu_destroy(pdu);
163 
164  return dgram;
165 }
WTP_PDU * wtp_pdu_create(int type)
Definition: wtp_pdu.c:67
static unsigned short send_tid(unsigned short tid)
Definition: wtp_pack.c:291
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
union wtp_pdu::@107 u
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define wap_event_create(type)
Definition: wap_events.h:107
gw_assert(wtls_machine->packet_to_send!=NULL)
WAPEventName type
Definition: wap_events.h:88
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
union WAPEvent::@87 u
WAPEvent* wtp_pack_sar_ack ( long  ack_type,
long  tid,
WAPAddrTuple address,
int  psn 
)

Definition at line 263 of file wtp_pack.c.

References octstr_create_from_data, send_tid(), WAPEvent::u, wtp_pdu::u, wap_addr_tuple_duplicate(), wap_event_create, wtp_pdu_append_tpi(), wtp_pdu_create(), wtp_pdu_destroy(), and wtp_pdu_pack().

Referenced by process_sar_transaction().

264 {
265  WAPEvent *dgram = NULL;
266  WTP_PDU *pdu;
267  unsigned char cpsn = psn;
268 
269  pdu = wtp_pdu_create(Ack);
270  pdu->u.Ack.con = 1;
271  pdu->u.Ack.tidverify = ack_type;
272  pdu->u.Ack.rid = 0;
273  pdu->u.Ack.tid = send_tid(tid);
274 
275  wtp_pdu_append_tpi(pdu, 3, octstr_create_from_data((char*) &cpsn, 1));
276 
277  dgram = wap_event_create(T_DUnitdata_Req);
278  dgram->u.T_DUnitdata_Req.addr_tuple = wap_addr_tuple_duplicate(address);
279  dgram->u.T_DUnitdata_Req.user_data = wtp_pdu_pack(pdu);
280  wtp_pdu_destroy(pdu);
281 
282  return dgram;
283 }
WTP_PDU * wtp_pdu_create(int type)
Definition: wtp_pdu.c:67
void wtp_pdu_append_tpi(WTP_PDU *pdu, int type, Octstr *data)
Definition: wtp_pdu.c:153
long tid
Definition: wtp.h:190
static unsigned short send_tid(unsigned short tid)
Definition: wtp_pack.c:291
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
union wtp_pdu::@107 u
#define wap_event_create(type)
Definition: wap_events.h:107
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
union WAPEvent::@87 u
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
WAPEvent* wtp_pack_sar_result ( WTPRespMachine resp_machine,
int  psn 
)

Definition at line 167 of file wtp_pack.c.

References gw_assert(), octstr_copy, SAR_GROUP_LEN, SAR_SEGM_SIZE, send_tid(), WAPEvent::u, wtp_pdu::u, wap_addr_tuple_duplicate(), wap_event_create, wtp_pdu_create(), wtp_pdu_destroy(), and wtp_pdu_pack().

Referenced by begin_sar_result(), continue_sar_result(), and resend_sar_result().

168 {
169  WAPEvent *dgram = NULL;
170  WTP_PDU *pdu = NULL;
171  Octstr *data = NULL;
172  int gtr, ttr;
173 
174  gw_assert(machine->sar && machine->sar->data);
175 
176  if (psn > machine->sar->nsegm)
177  return dgram;
178 
179  ttr = psn == machine->sar->nsegm ? 1 : 0;
180  gtr = ttr ? 0 : (psn+1)%SAR_GROUP_LEN ? 0 : 1;
181 
182  if (gtr || ttr)
183  machine->sar->tr = 1;
184 
185  data = octstr_copy(machine->sar->data,psn*SAR_SEGM_SIZE,SAR_SEGM_SIZE);
186 
187  if (!psn) {
188  pdu = wtp_pdu_create(Result);
189  pdu->u.Result.con = 0;
190  pdu->u.Result.gtr = gtr;
191  pdu->u.Result.ttr = ttr;
192  pdu->u.Result.rid = 0;
193  pdu->u.Result.tid = send_tid(machine->tid);
194  pdu->u.Result.user_data = data;
195  } else {
196  pdu = wtp_pdu_create(Segmented_result);
197  pdu->u.Segmented_result.con = 0;
198  pdu->u.Segmented_result.gtr = gtr;
199  pdu->u.Segmented_result.ttr = ttr;
200  pdu->u.Segmented_result.rid = 0;
201  pdu->u.Segmented_result.tid = send_tid(machine->tid);
202  pdu->u.Segmented_result.psn = psn;
203  pdu->u.Segmented_result.user_data = data;
204  }
205 
206  dgram = wap_event_create(T_DUnitdata_Req);
207  dgram->u.T_DUnitdata_Req.addr_tuple =
208  wap_addr_tuple_duplicate(machine->addr_tuple);
209  dgram->u.T_DUnitdata_Req.user_data = wtp_pdu_pack(pdu);
210  wtp_pdu_destroy(pdu);
211 
212  return dgram;
213 }
WTP_PDU * wtp_pdu_create(int type)
Definition: wtp_pdu.c:67
static unsigned short send_tid(unsigned short tid)
Definition: wtp_pack.c:291
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
#define SAR_SEGM_SIZE
Definition: fakewap.c:221
union wtp_pdu::@107 u
#define wap_event_create(type)
Definition: wap_events.h:107
#define SAR_GROUP_LEN
Definition: fakewap.c:222
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
Octstr * wtp_pdu_pack(WTP_PDU *pdu)
Definition: wtp_pdu.c:388
void wtp_pdu_destroy(WTP_PDU *pdu)
Definition: wtp_pdu.c:104
union WAPEvent::@87 u
void wtp_pack_set_rid ( WAPEvent dgram,
long  rid 
)

Definition at line 215 of file wtp_pack.c.

References gw_assert(), octstr_set_bits(), WAPEvent::type, and WAPEvent::u.

Referenced by resend_sar_result().

216 {
217  gw_assert(dgram != NULL);
218  gw_assert(dgram->type == T_DUnitdata_Req);
219 
220  octstr_set_bits(dgram->u.T_DUnitdata_Req.user_data, 7, 1, rid);
221 }
void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, unsigned long value)
Definition: octstr.c:1847
gw_assert(wtls_machine->packet_to_send!=NULL)
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.