comparison src/g23m-fad/ppp/ppp_arbf.c @ 174:90eb61ecd093

src/g23m-fad: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2016 05:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
173:bf64d785238a 174:90eb61ecd093
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul :
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This modul is part of the entity PPP and implements all
18 | procedures and functions as described in the
19 | SDL-documentation (ARB-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef PPP_ARBF_C
24 #define PPP_ARBF_C
25 #endif /* !PPP_ARBF_C */
26
27 #define ENTITY_PPP
28
29 /*==== INCLUDES =============================================================*/
30
31 #include "typedefs.h" /* to get Condat data types */
32 #include "vsi.h" /* to get a lot of macros */
33 #include "macdef.h" /* to get a lot of macros */
34 #include "custom.h" /* to get a lot of macros */
35 #include "gsm.h" /* to get a lot of macros */
36 #include "cnf_ppp.h" /* to get cnf-definitions */
37 #include "mon_ppp.h" /* to get mon-definitions */
38 #include "prim.h" /* to get the definitions of used SAP and directions */
39 #include "dti.h" /* to get the DTILIB definitions */
40 #include "ppp.h" /* to get the global entity definitions */
41
42 #include "ppp_lcpf.h" /* to get function interface from lcp */
43 #include "ppp_papf.h" /* to get function interface from pap */
44 #include "ppp_capf.h" /* to get function interface from chap */
45 #include "ppp_ncpf.h" /* to get function interface from ncp */
46
47 /*==== CONST ================================================================*/
48
49 /*==== LOCAL VARS ===========================================================*/
50
51 /*==== PRIVATE FUNCTIONS ====================================================*/
52
53 /*==== PUBLIC FUNCTIONS =====================================================*/
54
55
56
57 /*
58 +------------------------------------------------------------------------------
59 | Function : arb_init
60 +------------------------------------------------------------------------------
61 | Description : The function arb_init() inizializes the arbitration (ARB)
62 |
63 | Parameters : no parameters
64 |
65 +------------------------------------------------------------------------------
66 */
67 GLOBAL void arb_init ()
68 {
69 TRACE_FUNCTION( "arb_init" );
70
71 /*
72 * initialize protocol-reject identifier
73 */
74 ppp_data->arb.pri = 1;
75 /*
76 * initialize time out counter
77 */
78 ppp_data->arb.to_counter = 1;
79 /*
80 * initialize pointer to last sent IPCP packet
81 */
82 ppp_data->arb.last_ipcp = NULL;
83
84
85 INIT_STATE( PPP_SERVICE_ARB , ARB_DEAD );
86
87 /*
88 * DTI channels
89 */
90
91 ppp_data->arb.dti_connect_state_prot = DTI_CLOSED;
92 ppp_data->arb.dti_connect_state_peer = DTI_CLOSED;
93 } /* arb_init() */
94
95
96
97 /*
98 +------------------------------------------------------------------------------
99 | Function : arb_discard_packet
100 +------------------------------------------------------------------------------
101 | Description : The function arb_discard_packet() frees the memory of
102 | the given packet
103 |
104 | Parameters : packet - pointer to a generic data descriptor
105 |
106 +------------------------------------------------------------------------------
107 */
108 GLOBAL void arb_discard_packet (T_desc2* packet)
109 {
110 T_desc2* temp_desc;
111 TRACE_FUNCTION( "arb_discard_packet" );
112
113 while(packet NEQ NULL)
114 {
115 temp_desc=(T_desc2*)packet->next;
116 MFREE(packet);
117 packet=temp_desc;
118 }
119 } /* arb_discard_packet() */
120
121
122
123 /*
124 +------------------------------------------------------------------------------
125 | Function : arb_get_protocol_reject
126 +------------------------------------------------------------------------------
127 | Description : The function arb_get_protocol_reject() creates
128 | a LCP protocol reject
129 |
130 | Parameters : ptype - packet type
131 | packet - packet which have to be rejected
132 | ptr_packet - returns a LCP protocol reject packet
133 |
134 +------------------------------------------------------------------------------
135 */
136 GLOBAL void arb_get_protocol_reject (USHORT ptype,
137 T_desc2* packet,
138 T_desc2** ptr_packet)
139 {
140 USHORT temp_len;
141 T_desc2* temp_desc;
142 T_desc2* ret_desc;
143
144 TRACE_FUNCTION( "arb_get_protocol_reject" );
145
146 /*
147 * 1 octet code field
148 * 1 octet identifier field
149 * 2 octets length field
150 * 2 octets rejected-protocol field
151 *----------
152 * 6 octets
153 */
154 MALLOC (ret_desc, (USHORT)(sizeof(T_desc2) - 1 + 6));
155 ret_desc->next = (ULONG)packet;
156 ret_desc->len = 6;
157
158 /*
159 * Code field for protocol reject
160 */
161 ret_desc->buffer[0] = CODE_PROT_REJ;
162
163 /*
164 * Identifier field
165 */
166 ret_desc->buffer[1] = ppp_data->arb.pri;/*lint !e415 (Warning -- access of out-of-bounds pointer) */
167
168 ppp_data->arb.pri++;
169
170 /*
171 * Length field
172 */
173 temp_len = 0;
174 packet = ret_desc;
175 while(packet NEQ NULL)
176 {
177 temp_len+= packet->len;
178 packet = (T_desc2*)packet->next;
179 }
180 if(temp_len > PPP_MRU_MIN)
181 temp_len=ppp_data->mru;
182 ret_desc->buffer[2] = (UBYTE)(temp_len >> 8);/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer) */
183 ret_desc->buffer[3] = (UBYTE)(temp_len & 0x00ff);/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer) */
184
185 /*
186 * Rejected-Protocol field
187 */
188 ret_desc->buffer[4] = (UBYTE)(ptype >> 8);/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer) */
189 ret_desc->buffer[5] = (UBYTE)(ptype & 0x00ff);/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer) */
190
191 /*
192 * cut the rejected packet if it is to long
193 */
194 packet = ret_desc;
195 while(temp_len > packet->len)
196 {
197 temp_len-= packet->len;
198 packet = (T_desc2*)packet->next;
199 }
200 packet->len = temp_len;
201 temp_desc = (T_desc2*)packet->next;
202 packet->next = (ULONG)NULL;
203 while(temp_desc NEQ NULL)
204 {
205 packet = (T_desc2*)temp_desc->next;
206 MFREE(temp_desc);
207 temp_desc = packet;
208 }
209 /*
210 * return created protocol reject packet
211 */
212 *ptr_packet = ret_desc;
213
214 /*lint -e415 -e416 (Warning -- access/creation of out-of-bounds pointer) */
215 } /* arb_get_protocol_reject() */
216
217
218
219 /*
220 +------------------------------------------------------------------------------
221 | Function : arb_get_pco_list
222 +------------------------------------------------------------------------------
223 | Description : The function arb_get_pco_list() creates the list of
224 | protocol configuratrion options as shown in 10.5.6.3/GSM 04.08
225 |
226 | Parameters : ptr_pco_list - returns list of protocol configuration options
227 |
228 +------------------------------------------------------------------------------
229 */
230 GLOBAL void arb_get_pco_list (T_sdu* ptr_pco_list)
231 {
232 UBYTE ap;
233 USHORT mru;
234 ULONG accm;
235 UBYTE pfc;
236 UBYTE acfc;
237
238 TRACE_FUNCTION( "arb_get_pco_list" );
239
240 /*
241 * initialize sdu
242 */
243 ptr_pco_list->o_buf=0;
244 ptr_pco_list->l_buf=0;
245
246 /*
247 * declare Configuration Protocol PPP
248 */
249 ptr_pco_list->buf[ptr_pco_list->l_buf]=0x80;
250 ptr_pco_list->l_buf++;
251
252 /*
253 * first packets are LCP packets
254 */
255 lcp_fill_out_packet(ptr_pco_list->buf, &ptr_pco_list->l_buf);
256 /*
257 * next packets may be authentication packets
258 */
259 if(ppp_data->pco_mask & PPP_PCO_MASK_AUTH_PROT)
260 {
261 lcp_get_values(&ap, &mru, &accm, &pfc, &acfc);
262 switch(ap)
263 {
264 case PPP_AP_PAP:
265 /*
266 * insert PAP authentication packet
267 */
268 pap_fill_out_packet(ptr_pco_list->buf, &ptr_pco_list->l_buf);
269 break;
270 case PPP_AP_CHAP:
271 /*
272 * insert CHAP authentication packets
273 */
274 chap_fill_out_packet(ptr_pco_list->buf, &ptr_pco_list->l_buf);
275 break;
276 }
277 }
278 /*
279 * next packet is the IPCP packet received from PPP peer
280 */
281 ncp_fill_out_packet(ptr_pco_list->buf, &ptr_pco_list->l_buf);
282 /*
283 * convert length in octet to length in bit
284 */
285 ptr_pco_list->l_buf=ptr_pco_list->l_buf << 3;
286
287 } /* arb_get_pco_list() */
288
289
290
291 /*
292 +------------------------------------------------------------------------------
293 | Function : arb_analyze_pco_list
294 +------------------------------------------------------------------------------
295 | Description : The function arb_analyze_pco_list() analyzes the given list of
296 | protocol configuration options and returns values of interest
297 |
298 | Parameters : pco_list - list of protocol configuration options
299 | ptr_dns1 - returns Primary DNS Server Address
300 | ptr_dns2 - returns Secondary DNS Server Address
301 | ptr_gateway - returns Gateway Address
302 |
303 +------------------------------------------------------------------------------
304 */
305 GLOBAL void arb_analyze_pco_list (T_sdu* pco_list,
306 ULONG* ptr_dns1,
307 ULONG* ptr_dns2,
308 ULONG* ptr_gateway)
309 {
310 USHORT pos;
311
312 TRACE_FUNCTION( "arb_analyze_pco_list" );
313
314 /*
315 * initialize return values
316 */
317 *ptr_dns1 = PPP_PDNS_DEFAULT;
318 *ptr_dns2 = PPP_SDNS_DEFAULT;
319 *ptr_gateway = PPP_GATEWAY_DEFAULT;
320
321 /*
322 * analyze pco list
323 */
324 pco_list->l_buf = pco_list->l_buf >> 3;
325 pco_list->o_buf = pco_list->o_buf >> 3;
326 pos = pco_list->o_buf;
327 if((pco_list->l_buf > 0) && (pco_list->buf[pos] EQ 0x80))
328 {
329 pos++;
330 while(pos < (pco_list->l_buf + pco_list->o_buf))
331 {
332 if((pco_list->buf[pos] EQ PROTOCOL_IPCP_MSB) &&
333 (pco_list->buf[pos + 1] EQ PROTOCOL_IPCP_LSB))
334 {
335 /*
336 * determine DNS addresses and Gateway address
337 */
338 ncp_analyze_pco (pco_list->buf, pos, ptr_dns1, ptr_dns2, ptr_gateway);
339 }
340 pos+= pco_list->buf[pos + 2] + 3;
341 }
342 }
343 } /* arb_analyze_pco_list() */
344
345 /*
346 +------------------------------------------------------------------------------
347 | Function : arb_dti_close_prot_ind
348 +------------------------------------------------------------------------------
349 | Description : Close the DTI Protocol Channel
350 |
351 | Parameters : no parameters
352 |
353 +------------------------------------------------------------------------------
354 */
355 GLOBAL void arb_dti_close_prot_ind ()
356 {
357 TRACE_FUNCTION("arb_dti_close_prot_ind");
358
359 switch (ppp_data->arb.dti_connect_state_prot)
360 {
361 case DTI_SETUP:
362 case DTI_IDLE:
363 dti_close(ppp_data->ppphDTI, PPP_INSTANCE,
364 PROT_LAYER, PROT_CHANNEL, FALSE);
365 ppp_data->arb.dti_connect_state_prot = DTI_CLOSED;
366 break;
367 default:
368 break;
369 }
370 } /* arb_dti_close_prot_ind */
371
372 /*
373 +------------------------------------------------------------------------------
374 | Function : arb_dti_close_peer_ind
375 +------------------------------------------------------------------------------
376 | Description : Close the DTI Peer Channel
377 |
378 | Parameters : no parameters
379 |
380 +------------------------------------------------------------------------------
381 */
382 GLOBAL void arb_dti_close_peer_ind ()
383 {
384 TRACE_FUNCTION("arb_dti_close_peer_ind");
385
386 switch (ppp_data->arb.dti_connect_state_peer)
387 {
388 case DTI_SETUP:
389 case DTI_IDLE:
390 dti_close(ppp_data->ppphDTI, PPP_INSTANCE,
391 PEER_LAYER, PEER_CHANNEL, FALSE);
392 ppp_data->arb.dti_connect_state_peer = DTI_CLOSED;
393 break;
394 default:
395 break;
396 }
397 } /* arb_dti_close_peer_ind */