blob: 24ed82f3fa3e660ad0efabf209780324702296da [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * dispatcher_if.c
40 *
41 * Project:
42 * --------
43 * VMOLY
44 *
45 * Description:
46 * ------------
47 * Dispatcher public interface implementation.
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 *******************************************************************************/
54
55#include "dispatcher_if.h"
56#include "dispatcher_struct.h"
57#include "global_def.h"
58#include "dispatcher_msgid.h"
59#include "qmu_bm_util.h"
60#include "md_sap.h"
61#include "dispatcher_debug.h"
62#include "dispatcher_data_path_trace_utmd.h"
63/**
64 * ipcore registered dl callback to dispatcher
65 */
66static dispatcher_dlvr_dl_did_f g_funcptr_ipcore_dl_did_cbk;
67static kal_bool wtunnel_cbk_set = KAL_FALSE;
68
69
70/**
71 * init function for dispatcher module
72 * init the global control context & register DL callback with wifi tunnel
73 */
74kal_bool dispatcher_init(void)
75{
76 //wtunnel_reg_dl_cbk(dispatcher_on_dl_did_cbk)
77 //DISPATCHER_REGISTER_DL_DID_CBK(dispatcher_on_dl_did_cbk);
78 //memset(g_dispatcher_cntx, 0, sizeof(g_dispatcher_cntx));
79 dispatcher_init_control_cntx();
80 MD_TRC_DISPATCHER_TR_INIT_ENTRY();
81 return KAL_TRUE;
82}
83
84
85/**
86 * reset function for dispatcher module
87 * reset the global control context & reset globals
88 */
89kal_bool dispatcher_reset(void)
90{
91 //memset(g_dispatcher_cntx, 0, sizeof(g_dispatcher_cntx));
92 dispatcher_init_control_cntx();
93 g_funcptr_ipcore_dl_did_cbk = NULL;
94 dispatcher_ctrl_set_current_protoidx(0);
95 MD_TRC_DISPATCHER_TR_RESET_ENTRY();
96 return KAL_TRUE;
97}
98
99
100/**
101 * ILM function for dispatcher module
102 * handle corresponding ILM for control path
103 * update the bearer and cid binding status to dispatcher control context
104 */
105void dispatcher_on_ilm(ilm_struct *p_ilm)
106{
107 kal_uint8 curr_protoidx = p_ilm->dest_mod_id - MOD_DISPATCHER;
108 dispatcher_ctrl_set_current_protoidx(curr_protoidx);
109 switch (p_ilm->msg_id) {
110 /*WO->DISPATCHER bearer related*/
111 case MSG_ID_N3EPC_DISPATCHER_BEARER_ACT_REQ:
112 if(KAL_FALSE == wtunnel_cbk_set) {
113 DISPATCHER_REGISTER_DL_DID_CBK(dispatcher_on_dl_did_cbk);
114 wtunnel_cbk_set = KAL_TRUE;
115 }
116 n3epc_dispatcher_bearer_act_req(
117 (n3epc_dispatcher_bearer_act_req_struct*)p_ilm->local_para_ptr);
118 break;
119
120 case MSG_ID_N3EPC_DISPATCHER_BEARER_DEACT_REQ:
121 n3epc_dispatcher_bearer_deact_req(
122 (n3epc_dispatcher_bearer_deact_req_struct*)p_ilm->local_para_ptr);
123 break;
124
125 /*WO->DISPATCHER binding related*/
126 case MSG_ID_N3EPC_DISPATCHER_PDN_BIND_REQ:
127 n3epc_dispatcher_pdn_bind_req(
128 (n3epc_dispatcher_pdn_bind_req_struct*)p_ilm->local_para_ptr,
129 p_ilm->src_mod_id);
130 break;
131
132 case MSG_ID_N3EPC_DISPATCHER_PDN_UNBIND_REQ:
133 n3epc_dispatcher_pdn_unbind_req(
134 (n3epc_dispatcher_pdn_unbind_req_struct*)p_ilm->local_para_ptr,
135 p_ilm->src_mod_id);
136 break;
137
138 /*DISPATCHER->IPCORE binding related*/
139 case MSG_ID_IPCORE_DISPATCHER_PDN_BIND_RSP:
140 ipcore_dispatcher_pdn_bind_rsp(
141 (ipcore_dispatcher_pdn_bind_rsp_struct*)p_ilm->local_para_ptr);
142 break;
143#ifdef ATEST_SYS_DISPATCHER
144 case MSG_ID_N3EPC_DISPATCHER_PDN_BIND_CNF:
145 case MSG_ID_N3EPC_DISPATCHER_PDN_UNBIND_CNF:
146 dispatcher_ut_handling_n3epc_ilm(p_ilm);
147 break;
148#endif
149 default:
150 MD_TRC_DISPATCHER_TR_ILM_WRONG_MSG_ID(p_ilm->msg_id);
151 break;
152 }
153}
154
155
156/**
157 * DL callback register to Dispatcher module
158 * Ipcore register its DL callback via this API
159 */
160void dispatcher_reg_cbk_dlvr_dl_did(dispatcher_dlvr_dl_did_f pf_dlvr_did)
161{
162 //need to set the ipcore dl callback
163 g_funcptr_ipcore_dl_did_cbk = pf_dlvr_did;
164
165}
166
167
168/******************************************************************
169****************Data path functions******************************
170*****************************************************************/
171
172/**
173 * DL callback from wifi tunnel (wtunnel->dispatcher->ipcore)
174 * 1. bearer id validataion first & convert to pdn_id
175 * 2. get binding state for pdn_id
176 * 3. forward data to ipcore by pdn_id
177 * 4. drop the DID if anything fails
178 */
179void dispatcher_on_dl_did_cbk(kal_uint8 bearer_id, upcm_did* p_head,
180 upcm_did* p_tail, kal_uint8 protocol_idx)
181{
182 //dispatch to the Ipcore by checking the dlcbk registered or not
183 kal_bool is_bearer_active = KAL_FALSE;
184 MD_TRC_DISPATCHER_DATA_TRACE_RCV_DL_DID(bearer_id, p_head, p_tail, protocol_idx);
185
186 if (IS_VALID_BEARERID(bearer_id))
187 {
188 is_bearer_active = dispatcher_check_is_bearer_active_by_bearerid(bearer_id, protocol_idx);
189 if (KAL_TRUE == is_bearer_active)
190 {
191 dispatcher_forward_dl_did_to_ipc(bearer_id, p_head, p_tail, protocol_idx);
192 return;
193 }
194 }
195 /*bearer id is not valid,drop did here*/
196 //upcm_did_dest_q(p_head, p_tail);
197 MD_TRC_DISPATCHER_TR_DL_DID_DROP_BEARER_STATS(bearer_id, is_bearer_active, p_head, p_tail);
198 DISPATCHER_DROP_DL_DID(bearer_id, p_head, p_tail, protocol_idx);
199}
200
201
202void dispatcher_forward_dl_did_to_ipc(kal_uint8 bearer_id, upcm_did* p_head,
203 upcm_did* p_tail, kal_uint8 protocol_idx)
204{
205 kal_uint32 pdn_id = 0;
206 DISPATCHER_CONVERT_BEARERID_TO_PDNID(bearer_id, pdn_id);
207 if (g_funcptr_ipcore_dl_did_cbk) {
208 MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_DL_DID(pdn_id, p_head, p_tail, protocol_idx);
209 g_funcptr_ipcore_dl_did_cbk(pdn_id, p_head, p_tail, protocol_idx);
210 } else {
211 MD_TRC_DISPATCHER_TR_DL_DID_DROP_NULL_CBK(p_head, p_tail);
212 DISPATCHER_DROP_DL_DID(bearer_id, p_head, p_tail, protocol_idx);
213 }
214}
215
216
217void dispatcher_drop_dl_did(kal_uint8 bearer_id, upcm_did* p_head,
218 upcm_did* p_tail, kal_uint8 protocol_idx)
219{
220 upcm_did_dest_q_free_buf(p_head, p_tail);
221}
222
223/**
224 * UL GPD flow (ipcore->dispatcher->wtunnel or UPCM)
225 * 1. ebi validataion first, is of wifi bearer, active
226 * 2. get binding state for ebi
227 * 3. forward data to wtunnel by bearerid
228 * 4. if not forward to wifitunnel, forward to UPCM
229 */
230void dispatcher_rcv_ul_gpd_by_ebi(kal_uint32 ebi, qbm_gpd* p_head, qbm_gpd* p_tail, kal_uint8 protocol_idx)
231{
232 kal_bool is_bearer_active = KAL_FALSE;
233 dispatcher_bind_state_enum bind_state;
234 /*bearer id value is of wifi & bearer is bind with dispatcher*/
235 MD_TRC_DISPATCHER_DATA_TRACE_RCV_UL_GPD_BY_EBI(ebi, p_head, p_tail, protocol_idx);
236 if (IS_VALID_BEARERID(ebi))
237 {
238 is_bearer_active = dispatcher_check_is_bearer_active_by_bearerid(ebi, protocol_idx);
239 bind_state = dispatcher_get_bind_state_by_bearerid(ebi, protocol_idx);
240
241 if ((DISPATCHER_PDN_ST_BIND == bind_state) &&
242 (KAL_TRUE == is_bearer_active))
243 {
244 DISPATCHER_FORWARD_UL_GPD_WTUNNEL(ebi, p_head, p_tail, protocol_idx);
245 return;
246 }
247 }
248
249 DISPATCHER_FORWARD_UL_GPD_UPCM_BY_EBI(ebi, p_head, p_tail, protocol_idx);
250
251}
252
253
254/**
255 * UL GPD flow (ipcore->dispatcher->wtunnel or UPCM)
256 * 1. pdn_id validataion first & convert to bearer_id
257 * 2. get binding state for pdn_id
258 * 3. forward data to wtunnel by bearerid
259 * 4. drop the DID if anything fails
260 * 5. if pdn_id not of wifi, forward to UPCM
261 */
262void dispatcher_rcv_ul_gpd_by_pdn(ip_type_e ip_type, kal_uint32 pdn_id,
263 qbm_gpd* p_head, qbm_gpd* p_tail,
264 kal_uint8 protocol_idx)
265{
266 /*pdn_id belong to wifi pdn*/
267 MD_TRC_DISPATCHER_DATA_TRACE_RCV_UL_GPD(pdn_id, p_head, p_tail, protocol_idx);
268 if (IS_PDNID_OF_WIFI(pdn_id))
269 {
270 dispatcher_bind_state_enum bind_state = dispatcher_get_bind_state_by_pdnid(pdn_id, protocol_idx);
271 kal_bool is_bearer_active = dispatcher_check_is_bearer_active_by_pdnid(pdn_id, protocol_idx);
272 if ((DISPATCHER_PDN_ST_BIND == bind_state) &&
273 (KAL_TRUE == is_bearer_active))
274 {
275 //wifi tunnel ul gpd interface without ip_type
276 kal_uint8 bearer_id = 0;
277 DISPATCHER_CONVERT_PDNID_TO_BEARERID(pdn_id, bearer_id);
278 DISPATCHER_FORWARD_UL_GPD_WTUNNEL(bearer_id, p_head, p_tail, protocol_idx);
279 } else {
280 //should drop this here
281 MD_TRC_DISPATCHER_TR_UL_GPD_DROP(pdn_id, is_bearer_active, bind_state, p_head, p_tail);
282 DISPATCHER_DROP_UL_GPD(pdn_id, p_head, p_tail, protocol_idx);
283 }
284 } else {
285 //call UPCM UL GPD interface
286 MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_UL_GPD_UPCM(pdn_id, p_head, p_tail, protocol_idx);
287 DISPATCHER_FORWARD_UL_GPD_UPCM(ip_type, pdn_id, p_head, p_tail, protocol_idx);
288 }
289}
290
291
292void dispatcher_drop_ul_gpd(kal_uint32 pdn_id, qbm_gpd* p_head,
293 qbm_gpd* p_tail, kal_uint8 protocol_idx)
294{
295 qbmt_dest_q(p_head, p_tail);
296}
297
298
299/**
300 * dispatcher UL META interface IPCORE->Dispatcher->wtunnel or UPCM)
301 * meta Q query to lhif & process each meta index
302 * if meta belong to wifi pdn then convert to gpd & keep accumulate for same PDN
303 * forward the gpd list to wtunnel
304 * forward the lhif q to upcm to release meta
305 */
306void dispatcher_rcv_ul_meta_queue(kal_uint16 start_idx, kal_uint16 end_idx,
307 LHIF_QUEUE_TYPE queue_type)
308{
309 kal_uint16 read_idx;
310 lhif_meta_tbl_t *meta_tbl;
311 lhif_meta_tbl_t *meta;
312 kal_uint16 tbl_size;
313
314 qbm_gpd *head_gpd_p = NULL;
315 qbm_gpd *tail_gpd_p = NULL;
316 kal_uint8 previous_bearer_id = 0;
317 kal_uint8 previous_proto_idx = 0;
318
319 read_idx = start_idx;
320 MD_TRC_DISPATCHER_DATA_TRACE_RCV_UL_META(queue_type, start_idx, end_idx);
321 //Query meta table
322 DIPSTACHER_QUERY_META_TBL((kal_uint32 **)&meta_tbl, &tbl_size, queue_type);
323 //check each meta index and process
324 do {
325 meta = &meta_tbl[read_idx];
326 //meta is not ignore & pdn state is bind
327
328 if (!meta->ignore && IS_PDNID_OF_WIFI(meta->pdn))
329 {
330 //check bind & bearer status both
331 dispatcher_bind_state_enum bind_state = dispatcher_get_bind_state_by_pdnid(meta->pdn, meta->protocol_idx);
332 kal_bool is_bearer_active = dispatcher_check_is_bearer_active_by_pdnid(meta->pdn, meta->protocol_idx);
333
334 if ((DISPATCHER_PDN_ST_BIND == bind_state) &&
335 (KAL_TRUE == is_bearer_active))
336 {
337 kal_uint8 curr_bearer_id;
338 kal_uint8 curr_proto_idx;
339 kal_uint8 *ip_packet = NULL;
340 kal_uint32 length = 0;
341 qbm_gpd *curr_gpd_p;
342 kal_uint8 *gpd_data_p;
343 DISPATCHER_CONVERT_PDNID_TO_BEARERID(meta->pdn, curr_bearer_id);
344 curr_proto_idx = meta->protocol_idx;
345 length = meta->length;
346 ip_packet = meta->vrb_addr;
347 if (1 != qbmt_alloc_q_no_tail(QBM_TYPE_NET_UL_SHRD,
348 1,
349 (void**) &curr_gpd_p,
350 (void**) &curr_gpd_p))
351 {
352 //gpd allocation failed
353 MD_TRC_DISPATCHER_TR_GPD_ALLOC_FAILED(read_idx);
354 meta->ignore = KAL_TRUE;
355 DISPATCHER_FREE_META_VRB(meta);
356 goto drop;
357 }
358 MD_TRC_DISPATCHER_DATA_TRACE_ALLOC_GPD_INFO(read_idx, meta->pdn, curr_gpd_p);
359 QBM_CACHE_INVALID(ip_packet, length);
360 //find the data ptr
361 dispatcher_utils_set_gpd_datalen(curr_gpd_p, length, (void**) &gpd_data_p);
362 kal_mem_cpy(gpd_data_p, ip_packet, length);
363 QBM_CACHE_FLUSH(gpd_data_p, length);
364
365 meta->ignore = KAL_TRUE;
366 //dpcopro_rbuf_release(meta->vrb_addr, meta->length);
367 DISPATCHER_FREE_META_VRB(meta);
368
369 if ((NULL == head_gpd_p) && (NULL == tail_gpd_p))
370 {
371 head_gpd_p = tail_gpd_p = curr_gpd_p;
372 previous_bearer_id = curr_bearer_id;
373 previous_proto_idx = curr_proto_idx;
374 }
375 else
376 {
377 if ((previous_bearer_id == curr_bearer_id) &&
378 (previous_proto_idx == curr_proto_idx))
379 {
380 //prev & current gpd can be clubbed together so update tail gpd
381 QBM_DES_SET_NEXT(tail_gpd_p, curr_gpd_p);
382 tail_gpd_p = curr_gpd_p;
383 MD_TRC_DISPATCHER_DATA_TRACE_CLUB_GPD_INFO(head_gpd_p, tail_gpd_p);
384 }
385 else
386 {
387 //previous GPD & curr gpd are of different bearer or proto
388 //call made to wtunnel for previous gpd head tail
389 DISPATCHER_FORWARD_UL_GPD_WTUNNEL(previous_bearer_id,
390 head_gpd_p, tail_gpd_p, previous_proto_idx);
391 //now update the variable
392 previous_bearer_id = curr_bearer_id;
393 previous_proto_idx = curr_proto_idx;
394 head_gpd_p = tail_gpd_p = curr_gpd_p;
395 }
396 }
397 } /*PDN state is not bind and by any how the ipcore has send this to Dispatcher*/
398 else
399 {
400 /*PDN is in range of wifi PDN & not bind*/
401 MD_TRC_DISPATCHER_TR_IGR_META_INDEX(read_idx, meta->pdn, bind_state, is_bearer_active);
402 meta->ignore = KAL_TRUE;
403 //dpcopro_rbuf_release(meta->vrb_addr, meta->length);
404 DISPATCHER_FREE_META_VRB(meta);
405 }
406 }
407
408drop:
409 read_idx ++;
410 if (read_idx == tbl_size) {
411 read_idx = 0;
412 }
413 } while (read_idx != end_idx);
414
415 /*if any allocated gpd is there*/
416 if(head_gpd_p) {
417 DISPATCHER_FORWARD_UL_GPD_WTUNNEL(previous_bearer_id, head_gpd_p,
418 tail_gpd_p, previous_proto_idx);
419 }
420 /*forward to upcm to release meta & process non wifi pdn meta idxs*/
421 MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_UL_META(queue_type, start_idx, end_idx);
422 DISPATCHER_FORWARD_UL_META_UPCM(start_idx, end_idx, queue_type);
423}
424
425
426kal_bool dispatcher_wtunnel_ul_send(kal_uint8 bearer_id, qbm_gpd *head,
427 qbm_gpd *tail, kal_uint8 proto_idx)
428{
429 MD_TRC_DISPATCHER_DATA_TRACE_FORWARD_UL_GPD_WTUNNEL(bearer_id, head, tail, proto_idx);
430 //actual wtunnel cbk here
431 wtunnel_upp_ul_send(bearer_id, head, tail, proto_idx);
432 return KAL_TRUE;
433}
434
435
436
437void dispatcher_utils_set_gpd_datalen(void *p_gpd, kal_uint32 datalen,
438 void **p_payload)
439{
440 kal_uint8* p_data = NULL;
441
442 ASSERT(p_gpd && p_payload);
443
444 if (QBM_DES_GET_BDP(p_gpd)) {
445 void* p_bd = NULL;
446
447 /* set p_bd data ptr */
448 p_bd = QBM_DES_GET_DATAPTR(p_gpd);
449
450 p_data = (kal_uint8*) QBM_DES_GET_DATAPTR(p_bd);
451
452 /* set p_bd data len */
453 QBM_DES_SET_DATALEN(p_bd, datalen);
454
455 /* set p_bd checksum */
456 qbm_cal_set_checksum(p_bd);
457 } else {
458 p_data = (kal_uint8*) QBM_DES_GET_DATAPTR(p_gpd);
459 }
460
461 /* set p_gpd data len */
462 QBM_DES_SET_DATALEN(p_gpd, datalen);
463
464 /* set p_gpd checksum */
465 qbm_cal_set_checksum(p_gpd);
466
467 *p_payload = (void*)(p_data);
468}
469
470
471/*adding for mini dump , reset sensitive data*/
472#if defined(__SENSITIVE_DATA_MOSAIC__)
473void dispatcher_module_clean(void)
474{
475 dispatcher_clean_private_data();
476}
477#endif