blob: 4f93146268f8cb73d5765d6e3fcc08703d1d7240 [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 * ipc_api.h
40 *
41 * Project:
42 * --------
43 * TATAKA
44 *
45 * Description:
46 * ------------
47 * IP Core public structure and interface definition.
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 *==============================================================================
54 * HISTORY
55 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56 *------------------------------------------------------------------------------
57 * removed!
58 *
59 * removed!
60 * removed!
61 * removed!
62 * removed!
63 *
64 * removed!
65 * removed!
66 * removed!
67 * removed!
68 *
69 * removed!
70 * removed!
71 * removed!
72 * removed!
73 * removed!
74 * removed!
75 * removed!
76 * removed!
77 *
78 * removed!
79 * removed!
80 * removed!
81 * removed!
82 *
83 * removed!
84 * removed!
85 * removed!
86 * removed!
87 *
88 * removed!
89 * removed!
90 * removed!
91 *
92 * removed!
93 * removed!
94 * removed!
95 *
96 * removed!
97 * removed!
98 * removed!
99 * removed!
100 *
101 * removed!
102 * removed!
103 * removed!
104 *
105 * removed!
106 * removed!
107 * removed!
108 *
109 * removed!
110 * removed!
111 * removed!
112 *
113 * removed!
114 * removed!
115 *
116 * removed!
117 * removed!
118 *
119 * removed!
120 * removed!
121 * removed!
122 * removed!
123 * removed!
124 * removed!
125 *
126 * removed!
127 * removed!
128 * removed!
129 * removed!
130 * removed!
131 *
132 * removed!
133 * removed!
134 * removed!
135 *
136 * removed!
137 * removed!
138 * removed!
139 *
140 * removed!
141 * removed!
142 * removed!
143 *
144 * removed!
145 * removed!
146 * removed!
147 * removed!
148 *
149 * removed!
150 * removed!
151 * removed!
152 *
153 * removed!
154 * removed!
155 * removed!
156 * removed!
157 *
158 * removed!
159 * removed!
160 * removed!
161 * removed!
162 *
163 * removed!
164 * removed!
165 * removed!
166 * removed!
167 *
168 * removed!
169 * removed!
170 * removed!
171 *
172 * removed!
173 * removed!
174 * removed!
175 *
176 * removed!
177 * removed!
178 * removed!
179 *
180 * removed!
181 * removed!
182 * removed!
183 * removed!
184 * removed!
185 *
186 * removed!
187 * removed!
188 * removed!
189 * removed!
190 * removed!
191 *
192 * removed!
193 * removed!
194 * removed!
195 * removed!
196 *
197 * removed!
198 * removed!
199 * removed!
200 *
201 * removed!
202 * removed!
203 * removed!
204 * removed!
205 *
206 * removed!
207 * removed!
208 * removed!
209 *
210 * removed!
211 * removed!
212 * removed!
213 *
214 * removed!
215 * removed!
216 * removed!
217 *
218 * removed!
219 * removed!
220 *
221 * removed!
222 * removed!
223 * removed!
224 * removed!
225 *
226 * removed!
227 * removed!
228 * removed!
229 *
230 * removed!
231 * removed!
232 *
233 * removed!
234 * removed!
235 * removed!
236 *
237 * removed!
238 * removed!
239 *
240 * removed!
241 * removed!
242 * removed!
243 * removed!
244 * removed!
245 *
246 * removed!
247 * removed!
248 * removed!
249 * removed!
250 * removed!
251 * removed!
252 * removed!
253 * removed!
254 *
255 * removed!
256 * removed!
257 * removed!
258 * removed!
259 * removed!
260 * removed!
261 *
262 * removed!
263 * removed!
264 * removed!
265 * removed!
266 * removed!
267 * removed!
268 *
269 * removed!
270 * removed!
271 * removed!
272 * removed!
273 *
274 *
275 * removed!
276 * removed!
277 * removed!
278 * removed!
279 * removed!
280 *
281 * removed!
282 * removed!
283 * removed!
284 *
285 * removed!
286 * removed!
287 * removed!
288 *
289 * removed!
290 * removed!
291 *
292 * removed!
293 * removed!
294 * removed!
295 *
296 * removed!
297 * removed!
298 * removed!
299 *
300 * removed!
301 * removed!
302 *
303 * removed!
304 * removed!
305 * removed!
306 *
307 * removed!
308 * removed!
309 *
310 * removed!
311 * removed!
312 *------------------------------------------------------------------------------
313 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
314 *==============================================================================
315 *******************************************************************************/
316#ifndef __INC_IPC_API_H
317#define __INC_IPC_API_H
318
319#include "hif_ior.h"
320#include "hif_mw_msgid.h" /*< expected to remove it when other other module include the header file */
321#include "lhif_if.h"
322
323#include "ipc_defs_public.h"
324#include "ipc_enums.h"
325#include "ipc_struct.h"
326
327/*------------------------------------------------------------------------------
328 * Data structure definition.
329 *----------------------------------------------------------------------------*/
330typedef struct _ipc_pkt_des_t {
331 ipc_pkt_des_type_e des_type;
332 kal_uint8 *packet;
333 kal_uint32 packet_len;
334 union {
335 struct {
336 qbm_gpd *gpd;
337 qbm_gpd *bd;
338 };
339 struct {
340 upcm_did *did;
341 kal_uint32 pkt_start_idx;
342 kal_uint16 psn;
343 };
344 struct {
345 lhif_meta_tbl_t *meta;
346 };
347 struct {
348 void *ipf_meta;
349 };
350 };
351 ipc_filter_t **matched_filter;
352 ipc_filter_info_t *filter_info;
353 kal_bool is_packet_info; /**< KAL_TRUE : Already parsed packet_info, KAL_FALSE : Not parsed packet_info yet */
354 ipc_packet_info_t *packet_info;
355 kal_uint8 ip_type;
356} ipc_pkt_des_t;
357
358typedef struct _ipc_pkt_t {
359 union {
360 kal_bool isGPD; /**< KAL_TRUE : Describe GPD list (with head/tail), KAL_FALSE : Describe single data buffer (with pointer/length) */
361 ipc_pkt_des_type_e buf_type; /**< Buffer type */
362 };
363
364 union {
365 /* Used if buf_type == IPC_PKT_DES_TYPE_GPD */
366 /* Used if isGPD == KAL_FALSE */
367 struct {
368 qbm_gpd *head; /**< Head of GPD List. Used if isGPD == KAL_TRUE */
369 qbm_gpd *tail; /**< Tail of GPD List. Used if isGPD == KAL_TRUE */
370 };
371
372 /* Used if buf_type == IPC_PKT_DES_TYPE_DID */
373 struct {
374 upcm_did *did_head; /**< Head of DID List. Used if buf_type == IPC_PKT_DES_TYPE_DID */
375 upcm_did *did_tail; /**< Tail of DID List. Used if buf_type == IPC_PKT_DES_TYPE_DID */
376 };
377
378 /* Used if buf_type == IPC_PKT_DES_TYPE_META */
379 struct {
380 kal_uint32 start_idx; /**< Start of meta List. Used if buf_type == IPC_PKT_DES_TYPE_META */
381 kal_uint32 end_idx; /**< End of DID List. Used if buf_type == IPC_PKT_DES_TYPE_META */
382 };
383 };
384
385 /* Used if buf_type == IPC_PKT_DES_TYPE_NO_DESC */
386 /* Used if isGPD == KAL_FALSE */
387 kal_uint8 *data; /**< Data pointer of buffer. Used if isGPD == KAL_FALSE */
388 kal_uint32 data_len; /**< Data pointer of buffer. Used if isGPD == KAL_FALSE */
389
390} ipc_pkt_t;
391/*------------------------------------------------------------------------------
392 * Helper Macro.
393 *----------------------------------------------------------------------------*/
394/*
395 * IPv4/IPv6 common.
396 */
397#define IPC_NE_GET_1B(_buf) \
398 ((kal_uint8)*((kal_uint8 *)(_buf)))
399#define IPC_NE_SET_1B(_buf, _value) \
400 do { \
401 *((kal_uint8 *)(_buf)) = (kal_uint8)(_value); \
402 } while (0)
403
404#ifndef IPC_ON_BIG_ENDIAN_PLATFORM /* little-endian platform */
405 #define IPC_NE_GET_2B(_buf) \
406 ( (((kal_uint16)*((kal_uint8 *)(_buf) + 0)) << 8) | \
407 (((kal_uint16)*((kal_uint8 *)(_buf) + 1)) << 0) )
408
409 #define IPC_NE_SET_2B(_buf, _value) \
410 do { \
411 *((kal_uint8 *)(_buf) + 0) = (kal_uint8)((_value) >> 8); \
412 *((kal_uint8 *)(_buf) + 1) = (kal_uint8)((_value) >> 0); \
413 } while (0)
414
415 #define IPC_NE_GET_4B(_buf) \
416 ( (((kal_uint32)*((kal_uint8 *)(_buf) + 0)) << 24) | \
417 (((kal_uint32)*((kal_uint8 *)(_buf) + 1)) << 16) | \
418 (((kal_uint32)*((kal_uint8 *)(_buf) + 2)) << 8) | \
419 (((kal_uint32)*((kal_uint8 *)(_buf) + 3)) << 0) )
420
421 #define IPC_NE_SET_4B(_buf, _value) \
422 do { \
423 *((kal_uint8 *)(_buf) + 0) = (kal_uint8)((_value) >> 24); \
424 *((kal_uint8 *)(_buf) + 1) = (kal_uint8)((_value) >> 16); \
425 *((kal_uint8 *)(_buf) + 2) = (kal_uint8)((_value) >> 8); \
426 *((kal_uint8 *)(_buf) + 3) = (kal_uint8)((_value) >> 0); \
427 } while (0)
428
429 #define IPC_H2N_2B(_value) \
430 (((kal_uint16)(_value) >> 8) | (((kal_uint16)(_value) & 0xff) << 8))
431
432#else /* big-endian platform */
433 #define IPC_NE_GET_2B(_buf) \
434 ( (((kal_uint16)*((kal_uint8 *)(_buf) + 0)) << 0) | \
435 (((kal_uint16)*((kal_uint8 *)(_buf) + 1)) << 8) )
436
437 #define IPC_NE_SET_2B(_buf, _value) \
438 do { \
439 *((kal_uint8 *)(_buf) + 0) = (kal_uint8)((_value) >> 0); \
440 *((kal_uint8 *)(_buf) + 1) = (kal_uint8)((_value) >> 8); \
441 } while (0)
442
443 #define IPC_NE_GET_4B(_buf) \
444 ( (((kal_uint32)*((kal_uint8 *)(_buf) + 0)) << 0) | \
445 (((kal_uint32)*((kal_uint8 *)(_buf) + 1)) << 8) | \
446 (((kal_uint32)*((kal_uint8 *)(_buf) + 2)) << 16) | \
447 (((kal_uint32)*((kal_uint8 *)(_buf) + 3)) << 24) )
448
449 #define IPC_NE_SET_4B(_buf, _value) \
450 do { \
451 *((kal_uint8 *)(_buf) + 0) = (kal_uint8)((_value) >> 0); \
452 *((kal_uint8 *)(_buf) + 1) = (kal_uint8)((_value) >> 8); \
453 *((kal_uint8 *)(_buf) + 2) = (kal_uint8)((_value) >> 16); \
454 *((kal_uint8 *)(_buf) + 3) = (kal_uint8)((_value) >> 24); \
455 } while (0)
456
457 #define IPC_H2N_2B(_value) \
458 ((kal_uint16)(_value))
459#endif
460
461#define IPC_HDR_IS_V4(_ip_hdr) \
462 (0x40 == (*((kal_uint8 *)(_ip_hdr)) & 0xf0))
463
464#define IPC_HDR_IS_V6(_ip_hdr) \
465 (0x60 == (*((kal_uint8 *)(_ip_hdr)) & 0xf0))
466
467
468#define IPC_CP_ADDR(_dst, _src, _len) \
469 kal_mem_cpy((_dst), (_src), (_len))
470
471#define IPC_EQ_ADDR(_addr1, _addr2, _len) \
472 (0 == kal_mem_cmp((_addr1), (_addr2), (_len)))
473
474#define IPC_EQ_2BYTE(_ptr1, _ptr2) \
475 ( ((*(kal_uint8 *)(_ptr1)) == (*((kal_uint8 *)(_ptr2)))) && \
476 ((*((kal_uint8 *)(_ptr1) + 1)) == (*(((kal_uint8 *)(_ptr2) + 1)))) )
477
478#define IPC_EQ_1BYTE(_ptr1, _ptr2) \
479 ((*(kal_uint8 *)(_ptr1)) == (*((kal_uint8 *)(_ptr2))))
480
481
482/*
483 * IANA IP Protocol Numbers.
484 * Ref: http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml
485 */
486#define IPC_HDR_PROT_IPV6_HOP 0 /* IPv6 Hop-by-Hop Option */
487#define IPC_HDR_PROT_ICMP 1 /* Internet Control Message */
488#define IPC_HDR_PROT_IGMP 2 /* Internet Group Message */
489#define IPC_HDR_PROT_IPV4_ENC 4 /* IPv4 encapsulation */
490#define IPC_HDR_PROT_TCP 6 /* Transmission Control */
491#define IPC_HDR_PROT_UDP 17 /* User Datagram */
492#define IPC_HDR_PROT_IPV6_ENC 41 /* IPv6 encapsulation */
493#define IPC_HDR_PROT_IPV6_ROUTE 43 /* Routing Header for IPv6 */
494#define IPC_HDR_PROT_IPV6_FRAG 44 /* Fragment Header for IPv6 */
495#define IPC_HDR_PROT_ESP 50 /* Encap Security Payload */
496#define IPC_HDR_PROT_AH 51 /* Authentication Header */
497#define IPC_HDR_PROT_ICMPV6 58 /* ICMP for IPv6 */
498#define IPC_HDR_PROT_IPV6_NONEXT 59 /* No Next Header for IPv6 */
499#define IPC_HDR_PROT_IPV6_DEST 60 /* Destination Options for IPv6 */
yu.dongc48ebcb2024-08-28 00:58:20 -0700500#define IPC_HDR_PROT_RESERVED 255 /* 255 is reserved in IANA IP Protocol Numbers */
yu.dongc33b3072024-08-21 23:14:49 -0700501
502/*
503 * IPv4.
504 */
505#define IPC_HDR_V4_ADDR_SIZE (4)
506#define IPC_HDR_V4_HEADER_SIZE (20)
507
508#define IPC_HDR_V4_GET_IHL(_ip_header) \
509 ((IPC_NE_GET_1B(_ip_header) & 0x0f) << 2)
510
511#define IPC_HDR_V4_SET_IHL(_ip_header, _ihl) \
512 do { \
513 IPC_NE_SET_1B(_ip_header, (IPC_NE_GET_1B(_ip_header) & 0xF0) | (((kal_uint8)(_ihl)>>2) & 0x0F)); \
514 } while (0)
515
516/*
517 * 2016/02/24 Peter.Hsu
518 * To support ECN, we extend existing DSCP API to cover ECN due to backward compatibility.
519 */
520
521/* Get/Set both DSCP & ECN (total 8 bits) */
522#define IPC_HDR_V4_GET_DSCP(_ip_header) \
523 (IPC_NE_GET_1B(((kal_uint8*)(_ip_header)) + 1))
524
525#define IPC_HDR_V4_SET_DSCP(_ip_header, _dscp_ecn) \
526 do { \
527 IPC_NE_SET_1B(((kal_uint8*)(_ip_header)) + 1, IPC_NE_GET_1B(((kal_uint8*)(_ip_header)) + 1) | (kal_uint8)(_dscp_ecn)); \
528 } while (0)
529
530#define IPC_HDR_V4_RESET_VER_IHL_DSCP_ECN(_ip_header) \
531 do { \
532 IPC_NE_SET_1B(_ip_header, 0x45); \
533 IPC_NE_SET_1B(((kal_uint8 *)(_ip_header)) + 1, 0x00); \
534 } while (0)
535
536#define IPC_HDR_V4_GET_TOTAL_LENGTH(_ip_header) \
537 IPC_NE_GET_2B(((kal_uint8 *)(_ip_header)) + 2)
538
539#define IPC_HDR_V4_SET_TOTAL_LENGTH(_ip_header, _length) \
540 do { \
541 IPC_NE_SET_2B(((kal_uint8 *)(_ip_header)) + 2, _length); \
542 } while (0)
543
544#define IPC_HDR_V4_GET_IDENTITY(_ip_header) \
545 IPC_NE_GET_2B(((kal_uint8 *)(_ip_header)) + 4)
546
547#define IPC_HDR_V4_SET_IDENTITY(_ip_header, _id) \
548 do { \
549 IPC_NE_SET_2B(((kal_uint8 *)(_ip_header)) + 4, _id); \
550 } while (0)
551
552#define IPC_HDR_V4_GET_FLAGS(_ip_header) \
553 ((*(((kal_uint8 *)(_ip_header) + 6))) >> 5)
554
555#define IPC_HDR_V4_SET_FLAGS(_ip_header, _flags) \
556 do { \
557 IPC_NE_SET_1B(((kal_uint8*)(_ip_header)) + 6, (IPC_NE_GET_1B(((kal_uint8*)(_ip_header)) + 6) & 0x1F) | ((kal_uint8)(_flags) << 5));\
558 } while (0)
559
560#define IPC_HDR_V4_IS_MF(_ip_header) \
561 (IPC_HDR_V4_GET_FLAGS(_ip_header) & 0x04)
562
563#define IPC_HDR_V4_GET_FRAG_OFFSET(_ip_header) \
564 (IPC_NE_GET_2B(((kal_uint8 *)(_ip_header)) + 6) & 0x1fff)
565
566#define IPC_HDR_V4_SET_FRAG_OFFSET(_ip_header, _offset) \
567 do { \
568 IPC_NE_SET_2B((((kal_uint8 *)(_ip_header)) + 6), \
569 ((IPC_NE_GET_2B(((kal_uint8 *)(_ip_header)) + 6) & 0xe000) | \
570 ((kal_uint16)(_offset) & 0x1fff)) ); \
571 } while (0)
572
573#define IPC_HDR_V4_IS_FRAG(_ip_header) \
574 (IPC_HDR_V4_IS_MF(_ip_header) || (0 != IPC_HDR_V4_GET_FRAG_OFFSET(_ip_header)))
575
576#define IPC_HDR_V4_GET_TTL(_ip_header) \
577 IPC_NE_GET_1B(((kal_uint8 *)(_ip_header)) + 8)
578
579#define IPC_HDR_V4_SET_TTL(_ip_header, _ttl) \
580 do { \
581 IPC_NE_SET_1B(((kal_uint8 *)(_ip_header)) + 8, (kal_uint8)(_ttl)); \
582 } while (0)
583
584#define IPC_HDR_V4_GET_PROTOCOL(_ip_header) \
585 IPC_NE_GET_1B(((kal_uint8 *)(_ip_header)) + 9)
586
587#define IPC_HDR_V4_SET_PROTOCOL(_ip_header, _protocol) \
588 do { \
589 IPC_NE_SET_1B(((kal_uint8 *)(_ip_header)) + 9, (kal_uint8)(_protocol)); \
590 } while (0)
591
592#define IPC_HDR_V4_EQ_PROTOCOL(_ip_header, _protocol) \
593 (IPC_HDR_V4_GET_PROTOCOL(_ip_header) == (_protocol))
594
595#define IPC_HDR_V4_GET_HEADER_CHECKSUM(_ip_header) \
596 IPC_NE_GET_2B((kal_uint8 *)(_ip_header) + 10)
597
598#define IPC_HDR_V4_SET_HEADER_CHECKSUM(_ip_header, _checksum) \
599 do { \
600 IPC_NE_SET_2B((kal_uint8 *)(_ip_header) + 10, _checksum); \
601 } while (0)
602
603#define IPC_HDR_V4_GET_SRC_ADDR(_ip_header) \
604 ((kal_uint8 *)(_ip_header) + 12)
605
606#define IPC_HDR_V4_SET_SRC_ADDR(_ip_header, _src_ip_addr) \
607 do { \
608 IPC_CP_V4_ADDR(IPC_HDR_V4_GET_SRC_ADDR(_ip_header), _src_ip_addr); \
609 } while (0)
610
611#define IPC_HDR_V4_GET_DST_ADDR(_ip_header) \
612 ((kal_uint8 *)(_ip_header) + 16)
613
614#define IPC_HDR_V4_SET_DST_ADDR(_ip_header, _dst_ip_addr) \
615 do { \
616 IPC_CP_V4_ADDR(IPC_HDR_V4_GET_DST_ADDR(_ip_header), _dst_ip_addr); \
617 } while (0)
618
619#define IPC_HDR_V4_GET_NHPTR(_ip_header) \
620 ((kal_uint8 *)(_ip_header) + IPC_HDR_V4_GET_IHL(_ip_header))
621
622#define IPC_CP_V4_ADDR(_dst, _src) \
623 do { \
624 IPC_CP_ADDR(_dst, _src, IPC_HDR_V4_ADDR_SIZE); \
625 } while (0)
626
627#define IPC_EQ_V4_ADDR(_addr1, _addr2) \
628 IPC_EQ_ADDR(_addr1, _addr2, IPC_HDR_V4_ADDR_SIZE)
629
630#define IPC_IS_V4_CLASSA_ADDR(_addr) \
631 ( 0x00 == (*((kal_uint8 *)(_addr)) & 0xf0) )
632
633#define IPC_IS_V4_CLASSB_ADDR(_addr) \
634 ( 0x80 == (*((kal_uint8 *)(_addr)) & 0xf0) )
635
636#define IPC_IS_V4_CLASSC_ADDR(_addr) \
637 ( 0xc0 == (*((kal_uint8 *)(_addr)) & 0xf0) )
638
639#define IPC_IS_V4_CLASSD_ADDR(_addr) \
640 ( 0xe0 == (*((kal_uint8 *)(_addr)) & 0xf0) )
641
642#define IPC_IS_V4_UNSPECIFIED_ADDR(_addr) \
643 ( 0 == *((kal_uint8*)(_addr)) && \
644 0 == *((kal_uint8*)(_addr)+1) && \
645 0 == *((kal_uint8*)(_addr)+2) && \
646 0 == *((kal_uint8*)(_addr)+3) )
647
648/*
649 * IPv6.
650 */
651#define IPC_HDR_V6_ADDR_SIZE (16)
652#define IPC_HDR_V6_HEADER_SIZE (40)
653#define IPC_HDR_V6_MAX_HOP (255)
654
655#define IPC_HDR_V6_LENGTH_OFFSET (4)
656#define IPC_HDR_V6_NH_TYPE_OFFSET (6)
657#define IPC_HDR_V6_HOP_LIMIT_OFFSET (7)
658#define IPC_HDR_V6_SRC_ADDR_OFFSET (8)
659#define IPC_HDR_V6_DST_ADDR_OFFSET (24)
660
661#define IPC_HDR_V6_GET_TC(_ip_header) \
662 ((IPC_NE_GET_2B(_ip_header) >> 4) & 0xff)
663
664#define IPC_HDR_V6_SET_TC(_ip_header, _tc) \
665 do { \
666 IPC_NE_SET_2B(_ip_header, \
667 ((IPC_NE_GET_2B(_ip_header) & 0xf00f) | (((kal_uint16)(_tc) & 0xff) << 4))); \
668 } while (0)
669
670#define IPC_HDR_V6_GET_FLOW_LABEL(_ip_header) \
671 (IPC_NE_GET_4B(_ip_header) & 0xfffff)
672
673#define IPC_HDR_V6_SET_FLOW_LABEL(_ip_header, _flow_label) \
674 do { \
675 IPC_NE_SET_4B(_ip_header, \
676 ((IPC_NE_GET_4B(_ip_header) & 0xfff00000) | ((kal_uint32)(_flow_label) & 0xfffff))); \
677 } while (0)
678
679#define IPC_HDR_V6_RESET_VER_TC_FL(_ip_header) \
680 do { \
681 kal_mem_set((kal_uint8 *)(_ip_header), 0, 4); \
682 *((kal_uint8 *)(_ip_header)) |= 0x60; \
683 } while (0)
684
685#define IPC_HDR_V6_GET_LENGTH(_ip_header) \
686 IPC_NE_GET_2B((kal_uint8 *)(_ip_header) + IPC_HDR_V6_LENGTH_OFFSET)
687
688#define IPC_HDR_V6_SET_LENGTH(_ip_header, _length) \
689 do { \
690 IPC_NE_SET_2B((kal_uint8 *)(_ip_header) + IPC_HDR_V6_LENGTH_OFFSET, _length); \
691 } while (0)
692
693#define IPC_HDR_V6_GET_NH_TYPE(_ip_header) \
694 IPC_NE_GET_1B(((kal_uint8 *)(_ip_header)) + IPC_HDR_V6_NH_TYPE_OFFSET)
695
696#define IPC_HDR_V6_SET_NH_TYPE(_ip_header, _type) \
697 do { \
698 IPC_NE_SET_1B(((kal_uint8 *)(_ip_header)) + IPC_HDR_V6_NH_TYPE_OFFSET, (kal_uint8)(_type)); \
699 } while (0)
700
701#define IPC_HDR_V6_GET_HOP_LIMIT(_ip_header) \
702 IPC_NE_GET_1B((kal_uint8 *)(_ip_header) + IPC_HDR_V6_HOP_LIMIT_OFFSET)
703
704#define IPC_HDR_V6_SET_HOP_LIMIT(_ip_header, _hop_limit) \
705 do { \
706 IPC_NE_SET_1B(((kal_uint8 *)(_ip_header)) + IPC_HDR_V6_HOP_LIMIT_OFFSET, (kal_uint8)(_hop_limit)); \
707 } while (0)
708
709#define IPC_HDR_V6_GET_SRC_ADDR(_ip_header) \
710 ((kal_uint8 *)(_ip_header) + IPC_HDR_V6_SRC_ADDR_OFFSET)
711
712#define IPC_HDR_V6_SET_SRC_ADDR(_ip_header, _src_ip_addr) \
713 do { \
714 IPC_CP_V6_ADDR(IPC_HDR_V6_GET_SRC_ADDR(_ip_header), _src_ip_addr); \
715 } while (0)
716
717#define IPC_HDR_V6_GET_DST_ADDR(_ip_header) \
718 ((kal_uint8 *)(_ip_header) + IPC_HDR_V6_DST_ADDR_OFFSET)
719
720#define IPC_HDR_V6_SET_DST_ADDR(_ip_header, _dst_ip_addr) \
721 do { \
722 IPC_CP_V6_ADDR(IPC_HDR_V6_GET_DST_ADDR(_ip_header), _dst_ip_addr); \
723 } while (0)
724
725#define IPC_HDR_V6_GET_NHPTR(_ip_header) \
726 ((kal_uint8 *)(_ip_header) + IPC_HDR_V6_HEADER_SIZE)
727
728#define IPC_HDR_V6_SET_DST_SOL_MCST_ADDR(_ip_header, _dst_ip_addr) \
729 do { \
730 *(IPC_HDR_V6_GET_DST_ADDR(_ip_header)) = 0xff; \
731 *(IPC_HDR_V6_GET_DST_ADDR(_ip_header) + 1) = 0x02; \
732 kal_mem_set(IPC_HDR_V6_GET_DST_ADDR(_ip_header) + 2, 0, 9); \
733 *(IPC_HDR_V6_GET_DST_ADDR(_ip_header) + 11) = 0x01; \
734 *(IPC_HDR_V6_GET_DST_ADDR(_ip_header) + 12) = 0xff; \
735 kal_mem_cpy(IPC_HDR_V6_GET_DST_ADDR(_ip_header) + 13, (kal_uint8 *)(_dst_ip_addr) + 13, 3); \
736 } while (0)
737
738#define IPC_HDR_V6EXT_GET_NH_TYPE(_ext_header) \
739 IPC_NE_GET_1B(_ext_header)
740
741#define IPC_HDR_V6EXT_GET_HDR_EXT_LEN(_ext_header) \
742 ((IPC_NE_GET_1B(((kal_uint8*)(_ext_header))+1) + 1) << 3)
743
744#define IPC_IS_V6_LINK_LOCAL_ADDR(_addr) \
745 ( (0xfe == IPC_NE_GET_1B(_addr)) && \
746 (0x80 == IPC_NE_GET_1B(((kal_uint8*)(_addr)) + 1)))
747
748#define IPC_IS_V6_GLOBAL_ADDR(_addr) \
749 ( 0x20 == (IPC_NE_GET_1B(_addr) & 0xe0) )
750
751#define IPC_IS_V6_UNSPECIFIED_ADDR(_addr) \
752 ( 0x00 == *((kal_uint8 *)(_addr)) && \
753 0x00 == *((kal_uint8 *)(_addr) + 1) && \
754 0x00 == *((kal_uint8 *)(_addr) + 2) && \
755 0x00 == *((kal_uint8 *)(_addr) + 3) && \
756 0x00 == *((kal_uint8 *)(_addr) + 4) && \
757 0x00 == *((kal_uint8 *)(_addr) + 5) && \
758 0x00 == *((kal_uint8 *)(_addr) + 6) && \
759 0x00 == *((kal_uint8 *)(_addr) + 7) && \
760 0x00 == *((kal_uint8 *)(_addr) + 8) && \
761 0x00 == *((kal_uint8 *)(_addr) + 9) && \
762 0x00 == *((kal_uint8 *)(_addr) + 10) && \
763 0x00 == *((kal_uint8 *)(_addr) + 11) && \
764 0x00 == *((kal_uint8 *)(_addr) + 12) && \
765 0x00 == *((kal_uint8 *)(_addr) + 13) && \
766 0x00 == *((kal_uint8 *)(_addr) + 14) && \
767 0x00 == *((kal_uint8 *)(_addr) + 15))
768
769#define IPC_IS_V6_MCST_ADDR(_addr) \
770 ( 0xff == IPC_NE_GET_1B(_addr) )
771
772#define IPC_CP_V6_ADDR(_dst, _src) \
773 IPC_CP_ADDR(_dst, _src, IPC_HDR_V6_ADDR_SIZE)
774
775#define IPC_EQ_V6_ADDR(_addr1, _addr2) \
776 IPC_EQ_ADDR(_addr1, _addr2, IPC_HDR_V6_ADDR_SIZE)
777
778/*
779 * IPv6 fragment header
780 */
781#define IPC_HDR_V6_FRAGMENT_HEADER_SIZE (8)
782
783/*
784 * UDP.
785 */
786#define IPC_HDR_UDP_HEADER_SIZE (8)
787
788#define IPC_HDR_UDP_GET_SRC_PORT(_udp) \
789 IPC_NE_GET_2B(_udp)
790
791#define IPC_HDR_UDP_SET_SRC_PORT(_udp, _src_port) \
792 IPC_NE_SET_2B((kal_uint8 *)(_udp), _src_port)
793
794#define IPC_HDR_UDP_EQ_SRC_PORT(_udp, _src_port) \
795 (IPC_HDR_UDP_GET_SRC_PORT(_udp) == (_src_port))
796
797#define IPC_HDR_UDP_GET_DST_PORT(_udp) \
798 IPC_NE_GET_2B((kal_uint8 *)(_udp) + 2)
799
800#define IPC_HDR_UDP_SET_DST_PORT(_udp, _dst_port) \
801 IPC_NE_SET_2B((kal_uint8 *)(_udp) + 2, _dst_port)
802
803#define IPC_HDR_UDP_EQ_DST_PORT(_udp, _dst_port) \
804 (IPC_HDR_UDP_GET_DST_PORT(_udp) == (_dst_port))
805
806#define IPC_HDR_UDP_GET_LENGTH(_udp) \
807 IPC_NE_GET_2B((kal_uint8 *)(_udp) + 4)
808
809#define IPC_HDR_UDP_SET_LENGTH(_udp, _length) \
810 IPC_NE_SET_2B((kal_uint8 *)(_udp) + 4, _length)
811
812#define IPC_HDR_UDP_GET_CHECKSUM(_udp) \
813 IPC_NE_GET_2B((kal_uint8 *)(_udp) + 6)
814
815#define IPC_HDR_UDP_SET_CHECKSUM(_udp, _checksum) \
816 IPC_NE_SET_2B((kal_uint8 *)(_udp) + 6, _checksum)
817
818/*
819 * TCP.
820 */
821#define IPC_HDR_TCP_FLAG_FIN 0x01
822#define IPC_HDR_TCP_FLAG_SYN 0x02
823#define IPC_HDR_TCP_FLAG_RST 0x04 // Reset
824#define IPC_HDR_TCP_FLAG_PUSH 0x08
825#define IPC_HDR_TCP_FLAG_ACK 0x10
826#define IPC_HDR_TCP_FLAG_URG 0x20 // Urgent
827#define IPC_HDR_TCP_FLAG_ECE 0x40 // ECN Echo
828#define IPC_HDR_TCP_FLAG_CWR 0x80 // Congestion Window Reduced
829#define IPC_HDR_TCP_FLAG_NS 0x100 // ECN-nonce concealment protection (added to header by RFC 3540)
830
831
832#define IPC_HDR_TCP_HEADER_SIZE (20)
833
834#define IPC_HDR_TCP_GET_SRC_PORT(_tcp) \
835 IPC_NE_GET_2B(_tcp)
836
837#define IPC_HDR_TCP_SET_SRC_PORT(_tcp, _src_port) \
838 IPC_NE_SET_2B(_tcp, _src_port)
839
840#define IPC_HDR_TCP_EQ_SRC_PORT(_tcp, _src_port) \
841 (IPC_HDR_TCP_GET_SRC_PORT(_tcp) == (_src_port))
842
843#define IPC_HDR_TCP_GET_DST_PORT(_tcp) \
844 IPC_NE_GET_2B((kal_uint8 *)(_tcp) + 2)
845
846#define IPC_HDR_TCP_SET_DST_PORT(_tcp, _dst_port) \
847 IPC_NE_SET_2B((kal_uint8 *)(_tcp) + 2, _dst_port)
848
849#define IPC_HDR_TCP_EQ_DST_PORT(_tcp, _dst_port) \
850 (IPC_HDR_TCP_GET_DST_PORT(_tcp) == (_dst_port))
851
852#define IPC_HDR_TCP_GET_SEQ_NUM(_tcp) \
853 IPC_NE_GET_4B((kal_uint8 *)(_tcp) + 4)
854
855#define IPC_HDR_TCP_SET_SEQ_NUM(_tcp, _seq_num) \
856 IPC_NE_SET_4B((kal_uint8 *)(_tcp) + 4, _seq_num)
857
858#define IPC_HDR_TCP_EQ_SEQ_NUM(_tcp, _seq_num) \
859 (IPC_HDR_TCP_GET_SEQ_NUM(_tcp) == (_seq_num))
860
861#define IPC_HDR_TCP_GET_ACK_NUM(_tcp) \
862 IPC_NE_GET_4B((kal_uint8 *)(_tcp) + 8)
863
864#define IPC_HDR_TCP_SET_ACK_NUM(_tcp, _ack_num) \
865 IPC_NE_SET_4B((kal_uint8 *)(_tcp) + 8, _ack_num)
866
867#define IPC_HDR_TCP_EQ_ACK_NUM(_tcp, _ack_num) \
868 (IPC_HDR_TCP_GET_ACK_NUM(_tcp) == (_ack_num))
869
870#define IPC_HDR_TCP_GET_OFFSET(_tcp) \
871 ((IPC_NE_GET_1B((kal_uint8 *)(_tcp) + 12) & 0xF0) >> 2)
872
873#define IPC_HDR_TCP_SET_OFFSET(_tcp, _offset) \
874 do { \
875 IPC_NE_SET_1B((kal_uint8 *)(_tcp) + 12, (IPC_NE_GET_1B((kal_uint8 *)(_tcp) + 12) & 0x0F) | ((((kal_uint8)(_offset)>>2)<<4) & 0xF0)); \
876 } while (0)
877
878#define IPC_HDR_TCP_GET_RESERVED(_tcp) \
879 ((IPC_NE_GET_1B((kal_uint8 *)(_tcp) + 12) >> 1) & 0x07)
880
881#define IPC_HDR_TCP_SET_RESERVED(_tcp, _reserved) \
882 do { \
883 IPC_NE_SET_1B((kal_uint8 *)(_tcp) + 12, (IPC_NE_GET_1B((kal_uint8 *)(_tcp) + 12) & 0xF1) | (((kal_uint8)(_reserved) << 1) & 0x0E)); \
884 } while (0)
885
886#define IPC_HDR_TCP_GET_FLAGS(_tcp) \
887 (IPC_NE_GET_2B((kal_uint8 *)(_tcp) + 12) & 0x01FF)
888
889#define IPC_HDR_TCP_SET_FLAGS(_tcp, _flags) \
890 do { \
891 IPC_NE_SET_2B((kal_uint8 *)(_tcp) + 12, (IPC_NE_GET_2B((kal_uint8 *)(_tcp) + 12) & 0xFE00) | ((_flags) & 0x01FF)); \
892 } while (0)
893
894#define IPC_HDR_TCP_GET_WINDOW(_tcp) \
895 IPC_NE_GET_2B((kal_uint8 *)(_tcp) + 14)
896
897#define IPC_HDR_TCP_SET_WINDOW(_tcp, _window) \
898 IPC_NE_SET_2B((kal_uint8 *)(_tcp) + 14, _window)
899
900#define IPC_HDR_TCP_GET_CHECKSUM(_tcp) \
901 IPC_NE_GET_2B((kal_uint8 *)(_tcp) + 16)
902
903#define IPC_HDR_TCP_SET_CHECKSUM(_tcp, _checksum) \
904 IPC_NE_SET_2B((kal_uint8 *)(_tcp) + 16, _checksum)
905
906#define IPC_HDR_TCP_GET_URGENT_PTR(_tcp) \
907 IPC_NE_GET_2B((kal_uint8 *)(_tcp) + 18)
908
909#define IPC_HDR_TCP_SET_URGENT_PTR(_tcp, _urp) \
910 IPC_NE_SET_2B((kal_uint8 *)(_tcp) + 18, _urp)
911/*
912 * ICMP.
913 */
914#define IPC_HDR_ICMP_HEADER_SIZE (8)
915
916#define IPC_HDR_ICMP_TYPE_ECHO_REQUEST (8)
917#define IPC_HDR_ICMP_TYPE_ECHO_REPLY (0)
918#define IPC_HDR_ICMP_TYPE_RS (10)
919#define IPC_HDR_ICMP_TYPE_RA (9)
920
921#define IPC_HDR_ICMPV6_TYPE_ECHO_REQUEST (128)
922#define IPC_HDR_ICMPV6_TYPE_ECHO_REPLY (129)
923#define IPC_HDR_ICMPV6_TYPE_RS (133)
924#define IPC_HDR_ICMPV6_TYPE_RA (134)
925
926#define IPC_HDR_ICMP_GET_TYPE(_icmp) \
927 IPC_NE_GET_1B(_icmp)
928
929#define IPC_HDR_ICMP_SET_TYPE(_icmp, _type) \
930 IPC_NE_SET_1B(_icmp, _type)
931
932#define IPC_HDR_ICMP_EQ_TYPE(_icmp, _type) \
933 (IPC_HDR_ICMP_GET_TYPE(_icmp) == (_type))
934
935#define IPC_HDR_ICMP_GET_CODE(_icmp) \
936 IPC_NE_GET_1B((kal_uint8 *)(_icmp) + 1)
937
938#define IPC_HDR_ICMP_SET_CODE(_icmp, _code) \
939 IPC_NE_SET_1B((kal_uint8 *)(_icmp) + 1, (_code))
940
941#define IPC_HDR_ICMP_EQ_CODE(_icmp, _code) \
942 (IPC_HDR_ICMP_GET_CODE(_icmp) == (_code))
943
944#define IPC_HDR_ICMP_GET_CHECKSUM(_icmp) \
945 IPC_NE_GET_2B((kal_uint8 *)(_icmp) + 2)
946
947#define IPC_HDR_ICMP_SET_CHECKSUM(_icmp, _checksum) \
948 IPC_NE_SET_2B((kal_uint8 *)(_icmp) + 2, _checksum)
949
950#define IPC_HDR_ICMP_SET_UNUSED(_icmp, _value) \
951 IPC_NE_SET_4B((kal_uint8 *)(_icmp) + 4, _value)
952/*
953 * Ports.
954 */
955#define IPC_PORT_BOOTPS (67)
956#define IPC_PORT_BOOTPC (68)
957
958/*
959 * Helper functions
960 */
961#define ipc_get_netif_id_from_l2p_chid(_ipc_l2p_enum, _chid) ((kal_uint32)(_ipc_l2p_enum | _chid))
962
963/*------------------------------------------------------------------------------
964 * Public functions.
965 *----------------------------------------------------------------------------*/
966/**
967 * Allow HIF side module, such as ethercore or ppp, to register callback functions,
968 * callback context, and module id for a network interface.
969 *
970 * @param config [IN] The information required to regerster a network interface.
971 * @param handle [OUT] Caller allocated space to store a handle to the network interface attached.
972 * It returns a IPC_INVALID_HANDLE if failed.
973 *
974 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
975 */
976kal_bool ipc_attach(ipc_conf_t *config, ipc_handle_t *handle);
977
978/**
979 * Detach the network interface.
980 *
981 * @param handle [IN] Handle to the network interface to detach.
982 *
983 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
984 */
985kal_bool ipc_detach(ipc_handle_t handle);
986
987/**
988 * Send a list of IP datagrams to wireless network.
989 *
990 * @param handle [IN] Handle to the network interface attached.
991 * @param ior [IN] It wraps up a set of uplink GPD to send.
992 *
993 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
994 */
995kal_bool ipc_uplink(ipc_handle_t handle, ipc_io_request_t *ior);
996
997/**
998 * Retrieve index of a set of IPv4/IPv6 addresses.
999 *
1000 * @param handle [IN] Handle to the network interface attached.
1001 *
1002 * @return Non-negtive value as a valid index, netgative value for an invalid one (e.g. before session established.).
1003 */
1004kal_int32 ipc_get_ip_id(ipc_handle_t handle);
1005
1006/**
1007 * Force reloading buffers for the network interface to receive uplink traffic.
1008 *
1009 * @param handle [IN] Handle to the network interface attached.
1010 */
1011void ipc_need_ul_reload(ipc_handle_t handle);
1012
1013/**
1014 * Check if any network interfaces need uplink reload retry,
1015 * if so, send an ILM to IPCORE to do uplink reload.
1016 */
1017void ipc_check_ul_reload_retry(void);
1018
1019/**
1020 * Manually notify the HIF network interface link/IP status changed. (This API does NOT change IP Core internal FSM !)
1021 *
1022 * @param netif_id [IN] The network interface ID.
1023 * @param ip_type [IN] Type of the PDN, IPC_IP_TYPE_IPV4, IPC_IP_TYPE_IPV6, or IPC_IP_TYPE_MIXED.
1024 * @param link_update[IN] KAL_TRUE if an IP session is established/deactived and link status is changed. KAL_FALSE if an IP information is updated for an activated IP session.
1025 * @param link_up [IN] (If link_update is KAL_TRUE) KAL_TRUE if an IP session is established, KAL_FALSE if an IP session is deactived ;
1026 (If link_update is KAL_FALSE) KAL_TRUE if new IP information is available, KAL_FALSE if original IP information is obsoleted
1027 */
1028void ipc_notify_link_change(kal_uint32 netif_id, kal_uint8 ip_type, kal_bool link_update, kal_bool is_up);
1029
1030/**
1031 * Install callback function and filtering rules for uplink traffic.
1032 *
1033 * @param rules [IN] Rules to filter of uplink IP datagrams.
1034 * @param callback_func [IN] Callback function for a uplink IP datagram matched the rules.
1035 * @param callback_context [IN] Context to pass in the callback function.
1036 *
1037 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1038 */
1039kal_int32 ipc_register_ul_filter_cbk(ipc_filter_rules_t *rules,
1040 ipc_filter_callback_t callback_func,
1041 void *callback_context);
1042
1043/**
1044 * Install callback function and filtering rules for downlink traffic.
1045 *
1046 * @param rules [IN] Rules to filter of downlink IP datagrams.
1047 * @param callback_func [IN] Callback function for a downlink IP datagram matched the rules.
1048 * @param callback_context [IN] Context to pass in the callback function.
1049 *
1050 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1051 */
1052kal_int32 ipc_register_dl_filter_cbk(ipc_filter_rules_t *rules,
1053 ipc_filter_callback_t callback_func,
1054 void *callback_context);
1055
1056/**
1057 * Install module ID and filtering rules for uplink traffic.
1058 *
1059 * @param rules [IN] Rules to filter of uplink IP datagrams.
1060 * @param callback_module [IN] Destination module of the MSG MSG_ID_IPCORE_UL_PACKET_FILTERED_REQ for a uplink IP datagram matched the rules.
1061 * @param callback_context [IN] Context to pass in the callback function.
1062 *
1063 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1064 */
1065kal_int32 ipc_register_ul_filter_msg(ipc_filter_rules_t *rules,
1066 module_type callback_module,
1067 void *callback_context);
1068
1069/**
1070 * Install module ID and filtering rules for downlink traffic.
1071 *
1072 * @param rules [IN] Rules to filter of downlink IP datagrams.
1073 * @param callback_module [IN] Destination module of the MSG MSG_ID_IPCORE_DL_PACKET_FILTERED_REQ for a downlink IP datagram matched the rules.
1074 * @param callback_context [IN] Context to pass in the callback function.
1075 *
1076 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1077 */
1078kal_int32 ipc_register_dl_filter_msg(ipc_filter_rules_t *rules,
1079 module_type callback_module,
1080 void *callback_context);
1081
1082/**
1083 * Install callback function and filtering rules for uplink traffic. (callback function with information as parameter)
1084 *
1085 * @param rules [IN] Rules to filter of uplink IP datagrams.
1086 * @param callback_func [IN] Callback function for a uplink IP datagram matched the rules (with information as parameter).
1087 * @param callback_context [IN] Context to pass in the callback function.
1088 *
1089 * @return Zero or positive value as filter ID if registration succeeded, negative value if it failed.
1090 */
1091kal_int32 ipc_register_ul_filter_with_info_cbk(ipc_filter_rules_t *rules,
1092 ipc_filter_with_info_callback_t callback_func,
1093 void *callback_context);
1094
1095/**
1096 * Install callback function and filtering rules for downlink traffic. (callback function with information as parameter)
1097 *
1098 * @param rules [IN] Rules to filter of downlink IP datagrams.
1099 * @param callback_func [IN] Callback function for a downlink IP datagram matched the rules (with information as parameter).
1100 * @param callback_context [IN] Context to pass in the callback function.
1101 *
1102 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1103 */
1104kal_int32 ipc_register_dl_filter_with_info_cbk(ipc_filter_rules_t *rules,
1105 ipc_filter_with_info_callback_t callback_func,
1106 void *callback_context);
1107
1108/**
1109 * Install module ID and filtering rules for uplink traffic. (callback function with information as parameter)
1110 *
1111 * @param rules [IN] Rules to filter of uplink IP datagrams.
1112 * @param callback_module [IN] Destination module of the MSG MSG_ID_IPCORE_UL_PACKET_FILTERED_WITH_INFO_REQ for a uplink IP datagram matched the rules.
1113 * @param callback_context [IN] Context to pass in the callback function.
1114 *
1115 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1116 */
1117kal_int32 ipc_register_ul_filter_with_info_msg(ipc_filter_rules_t *rules,
1118 module_type callback_module,
1119 void *callback_context);
1120
1121/**
1122 * Install module ID and filtering rules for downlink traffic. (callback function with information as parameter)
1123 *
1124 * @param rules [IN] Rules to filter of downlink IP datagrams.
1125 * @param callback_module [IN] Destination module of the MSG MSG_ID_IPCORE_DL_PACKET_FILTERED_WITH_INFO_REQ for a downlink IP datagram matched the rules.
1126 * @param callback_context [IN] Context to pass in the callback function.
1127 *
1128 * @return Zero or postive value as filter ID if registration succeeded, negative value if it failed.
1129 */
1130kal_int32 ipc_register_dl_filter_with_info_msg(ipc_filter_rules_t *rules,
1131 module_type callback_module,
1132 void *callback_context);
1133
1134/**
1135 * Uninstall the filter for uplink traffic.
1136 *
1137 * @param filter_id [IN] filter ID to unregister.
1138 */
1139void ipc_deregister_ul_filter(kal_int32 filter_id);
1140
1141/**
1142 * Uninstall the filter for donwlink traffic.
1143 *
1144 * @param filter_id [IN] filter ID to unregister.
1145 */
1146void ipc_deregister_dl_filter(kal_int32 filter_id);
1147
1148/**
1149 * Copy buffers in the GPD list to the buffer prepared by caller.
1150 *
1151 * @param dst_buffer [OUT] Destination buffer to copy to, which is prepared by caller.
1152 * @param dst_max_len [IN] Size of the destination buffer prepared by caller in bytes.
1153 * @param dst_len_copied [OUT] Number of bytes copied to the destination buffer.
1154 * @param src_head_gpd [IN] Head of the GPD list with source buffers to copy from.
1155 * @param src_tail_gpd [IN] Tail of the GPD list with source buffers to copy from.
1156 *
1157 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1158 */
1159kal_bool ipc_gpd_copy(kal_uint8 *dst_buffer, kal_uint32 dst_max_len, kal_uint32 *dst_len_copied, qbm_gpd *src_head_gpd, qbm_gpd *src_tail_gpd);
1160
1161/**
1162 * Pack datagram in GPD format and selectively fill L4(UDP) and IP header.
1163 *
1164 * @param uplink [IN] Uplink or downlink packet.
1165 * @param pkt [IN] Datagram or GPD list to sent.
1166 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1167 * @param head_gpd [OUT] Head of GPD list return
1168 * @param tail_gpd [OUT] Tail of GPD list return
1169 *
1170 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1171 */
1172kal_bool ipc_pack_pkt_public(kal_bool uplink,
1173 ipc_pkt_t *pkt,
1174 ipc_hdr_t *hdr,
1175 qbm_gpd **head_gpd,
1176 qbm_gpd **tail_gpd);
1177
1178/**
1179 * Send datagram in buffer or GPD list to the wireless netowrk and selectively fill L4(UDP) and IP header on each of them.
1180 *
1181 * @param pkt [IN] Datagram or GPD list to sent.
1182 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1183 * @param ebi [IN] EBI/NSAPI.
1184 *
1185 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1186 */
1187kal_bool ipc_send_ul_pkt(ipc_pkt_t *pkt, ipc_hdr_t *hdr, kal_uint32 ebi);
1188
1189/**
1190 * Send datagram in buffer or GPD list to the wireless netowrk and selectively fill L4(UDP) and IP header on each of them.
1191 *
1192 * @param pkt [IN] Datagram or GPD list to sent.
1193 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1194 * @param pdn [IN] PDN ID
1195 * @param ip_type [IN] Type of IP datagrams, see IPC_IP_TYPE_XXX defined for valid values. Note that only one of IPv4/IPv6 can be selected and MIX type is NOT allowed.
1196 *
1197 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1198 */
1199kal_bool ipc_send_ul_pkt_by_pdn(ipc_pkt_t *pkt,
1200 ipc_hdr_t *hdr,
1201 kal_uint32 pdn,
1202 kal_uint8 ip_type);
1203
1204/**
1205 * Send datagram in buffer or GPD list to the wireless netowrk and selectively fill L4(UDP) and IP header on each of them.
1206 *
1207 * @param pkt [IN] Datagram or GPD list to sent.
1208 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1209 * @param netif_id [IN] Network interface ID
1210 * @param ip_type [IN] Type of IP datagrams, see IPC_IP_TYPE_XXX defined for valid values. Note that only one of IPv4/IPv6 can be selected and MIX type is NOT allowed.
1211
1212 *
1213 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1214 */
1215kal_bool ipc_send_ul_pkt_by_netif_id(ipc_pkt_t *pkt,
1216 ipc_hdr_t *hdr,
1217 kal_uint32 netif_id,
1218 kal_uint8 ip_type);
1219
1220/**
1221 * Send datagram in buffer or GPD list to the wireless netowrk and selectively fill L4(UDP) and IP header on each of them.
1222 *
1223 * @param pkt [IN] Datagram or GPD list to sent.
1224 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1225 * @param ebi [IN] EBI/NSAPI.
1226 * @param proto_idx [IN] The index to distinquish from different SIM Card.
1227 *
1228 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1229 */
1230kal_bool ipc_send_ul_pkt_multiple_ps(ipc_pkt_t *pkt,
1231 ipc_hdr_t *hdr,
1232 kal_uint32 ebi,
1233 kal_uint8 proto_idx);
1234
1235/**
1236 * Send datagram in buffer or GPD list to the wireless netowrk and selectively fill L4(UDP) and IP header on each of them.
1237 *
1238 * @param pkt [IN] Datagram or GPD list to sent.
1239 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1240 * @param pdn [IN] PDN ID
1241 * @param ip_type [IN] Type of IP datagrams, see IPC_IP_TYPE_XXX defined for valid values. Note that only one of IPv4/IPv6 can be selected and MIX type is NOT allowed.
1242 * @param proto_idx [IN] The index to distinquish from different SIM Card.
1243 *
1244 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1245 */
1246kal_bool ipc_send_ul_pkt_by_pdn_multiple_ps(ipc_pkt_t *pkt,
1247 ipc_hdr_t *hdr,
1248 kal_uint32 pdn,
1249 kal_uint8 ip_type,
1250 kal_uint8 proto_idx);
1251
1252/**
1253* Send datagram in buffer or GPD list to the wireless netowrk after filtering and selectively fill L4(UDP) and IP header on each of them.
1254*
1255* @param pkt [IN] Datagram or GPD list to sent.
1256* @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1257* @param pdn [IN] PDN ID
1258* @param ip_type [IN] Type of IP datagrams, see IPC_IP_TYPE_XXX defined for valid values. Note that only one of IPv4/IPv6 can be selected and MIX type is NOT allowed.
1259* @param proto_idx [IN] The index to distinquish from different SIM Card.
1260*
1261* @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1262*/
1263kal_bool ipc_send_ul_pkt_on_normal_path_by_pdn_multiple_ps(ipc_pkt_t *pkt,
1264 ipc_hdr_t *hdr,
1265 kal_uint32 pdn,
1266 kal_uint8 ip_type,
1267 kal_uint8 proto_idx);
1268
1269/**
1270 * Send datagram in buffer or GPD list to the netowrk interface and selectively fill L4(UDP) and IP header on each of them.
1271 *
1272 * @param pkt [IN] Datagram or GPD list to sent.
1273 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1274 * @param netif_id [IN] Network interface ID.
1275 *
1276 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1277 */
1278kal_bool ipc_send_dl_pkt(ipc_pkt_t *pkt, ipc_hdr_t *hdr, kal_uint32 netif_id);
1279
1280/**
1281 * Register a notification.
1282 *
1283 * @param callback_func [IN] Callback function pointer.
1284 * @param callback_context [IN] Context to pass in the callback function.
1285 *
1286 * @return Zero or positive value as notification ID if registration succeeded, negative value otherwise.
1287 */
1288kal_int32 ipc_register_ntfy(ipc_ntfy_callback_t callback_func,
1289 void *callback_context);
1290
1291/**
1292 * Uninstall the registered notification.
1293 *
1294 * @param ntfy_id [IN] notification ID gotten from ipc_register_ntfy() to uninstall.
1295 */
1296void ipc_deregister_ntfy(kal_int32 ntfy_id);
1297
1298/**
1299 * Register link up indication handler
1300 *
1301 * @param module_id [IN] Module ID to handle ILM MSG_ID_IPCORE_LINK_UP_IND.
1302 *
1303 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1304 */
1305kal_bool ipc_register_link_up_ind_handler(module_type module_id);
1306
1307/**
1308 * Uninstall the registered link up indication handler
1309 */
1310void ipc_deregister_link_up_ind_handler(void);
1311
1312/**
1313 * Register IP up indication handler
1314 *
1315 * @param module_id [IN] Module ID to handle ILM MSG_ID_IPCORE_IP_UP_IND.
1316 *
1317 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1318 */
1319kal_bool ipc_register_ip_up_ind_handler(module_type module_id);
1320
1321/**
1322 * Uninstall the registered link up indication handler
1323 */
1324void ipc_deregister_ip_up_ind_handler(void);
1325
1326/**
1327 * Bind two lan netif to one another (for MD Direct Tethering)
1328 *
1329 * @param netif_id_1 [IN] lan netif ID.
1330 * @param netif_id_2 [IN] lan netif ID.
1331 */
1332void ipc_bind_lan_netif(kal_uint32 netif_id_1, kal_uint32 netif_id_2);
1333
1334/**
1335 * Unbind two lan netif from one another (for MD Direct Tethering)
1336 *
1337 * @param netif_id_1 [IN] lan netif ID.
1338 * @param netif_id_2 [IN] lan netif ID.
1339 */
1340void ipc_unbind_lan_netif(kal_uint32 netif_id_1, kal_uint32 netif_id_2);
1341
1342/**
1343 * Send a list of IP datagrams to wireless network. (Gen93)
1344 *
1345 * @param start_idx [IN] Start idx of the Meta list.
1346 * @param end_idx [IN] Start idx of the Meta list.
1347 * @param queue_type [IN] Type of the Meta queue.
1348 *
1349 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
1350 */
1351kal_bool ipc_meta_uplink(kal_uint16 start_idx, kal_uint16 end_idx, LHIF_QUEUE_TYPE queue_type);
1352
1353/**
1354 * Get pdn_id & protocol index by given netif ID
1355 *
1356 * @param netif_id [IN] The network interface ID.
1357 * @param ip_type [IN] The IP type of the queried PDN.
1358 * @param p_pdn_id [OUT] The result of the PDN ID.
1359 * @param p_proto_idx [OUT] The result of the protocol index.
1360 *
1361 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
1362 */
1363kal_bool ipc_find_pdn_id_by_netif_id(kal_uint32 netif_id, kal_uint8 ip_type, kal_uint32 *p_pdn_id, kal_uint8 *p_proto_idx);
1364
1365/**
1366 * Send datagram in buffer or DID list to the netowrk interface and selectively fill L4(UDP) and IP header on each of them. (Gen93)
1367 *
1368 * @param pkt [IN] Datagram or DID list to sent.
1369 * @param hdr [IN] UDP/IP header information which will be filled to sent packet(s). NULL pointer means "No packet modification is needed"
1370 * @param netif_id [IN] Network interface ID.
1371 *
1372 * @return KAL_TRUE if succeeded, KAL_FALSE otherwise.
1373 */
1374kal_bool ipc_send_dl_pkt_in_did(ipc_pkt_t *pkt, ipc_hdr_t *hdr, kal_uint32 netif_id);
1375
1376/**
1377 * Re-filtering API for ipc_fragment submoule to check the filtering result of the fragment packets. (Gen93)
1378 *
1379 * @param ip_type [IN] Type of the packet, either IPC_IP_TYPE_IPV4 or IPC_IP_TYPE_IPV6.
1380 * @param info [IN] Information for re-filtering.
1381 * @param p_head [OUT] Head of GPD list return
1382 * @param p_tail [OUT] Tail of GPD list return
1383 */
1384void ipc_frag_refilter(kal_uint8 ip_type, ipc_frag_refilter_info_t *info, qbm_gpd *p_head, qbm_gpd *p_tail);
1385
1386/**
1387 * Re-filtering API for ipc_fragment submoule to send fragment packets to AP when fragment collection timeout or exception. (Gen93)
1388 *
1389 * @param ip_type [IN] Type of the packet, either IPC_IP_TYPE_IPV4 or IPC_IP_TYPE_IPV6.
1390 * @param info [IN] Information for re-filtering.
1391 * @param p_head [OUT] Head of GPD list return
1392 * @param p_tail [OUT] Tail of GPD list return
1393 */
1394void ipc_frag_send_pkt(kal_uint8 ip_type, ipc_frag_refilter_info_t *info, qbm_gpd *p_head, qbm_gpd *p_tail);
1395
1396/*
1397 * Look into packet to gather necessary IP header & the upper layer protocol header information.
1398 * Note that, for IPv6's packet, current implementation don't handle the following cases and take them as not found:
1399 * #1. IPv6 packet with ESP header:
1400 * According to RFC 4303 section 3.1, everything after ESP header is encrypted.
1401 * Since we cannot decrypt it, we cannot acturally look into the upper layer protocol.
1402 *
1403 * #2. IPv6 extension header not defined in RFC 2460:
1404 * If necessary, we will handle them here according to corresponding RFC.
1405 *
1406 * #3. fragmentation:
1407 * No application needs IPv6 fragmentation on a modem platform so far.
1408 *
1409 * @param ipv6_packet [IN] The packet.
1410 * @param packet_len [IN] Length of the packet.
1411 * @param p_info [OUT] The necessary information gathered for later packete filtering.
1412 *
1413 * @return KAL_TRUE if the packet's information was gathered sucessfully, KAL_FALSE otherwise.
1414 */
1415kal_bool ipc_get_packet_info(kal_uint8 *p_packet, kal_uint16 packet_len, ipc_packet_info_t *p_info);
1416
1417/**
1418 * Send a list of IP datagrams filter-out by IPF. (Gen95)
1419 *
1420 * @param start_idx [IN] Start idx of the Meta list.
1421 * @param end_idx [IN] Start idx of the Meta list.
1422 * @param queue_type [IN] Type of the Meta queue.
1423 *
1424 */
1425void ipc_meta_downlink(kal_uint16 start_idx, kal_uint16 end_idx, kal_uint32 queue_type);
1426
1427/**
1428 * Query bound PDN id according to netif_id and ip_type
1429 *
1430 * @param netif_id [IN] network interface ID.
1431 * @param ip_type [IN] IPC_IP_TYPE_IPV4 / IPC_IP_TYPE_IPV6. (ipc_enums.h)
1432 * @param pdn_id [OUT] return the bound PDN ID.
1433 *
1434 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
1435 */
1436kal_bool ipc_query_pdn_by_netif(kal_uint32 netif_id, kal_uint8 ip_type, kal_int32 *pdn_id);
1437
1438/**
1439 * calculate TCP checksum
1440 *
1441 * @param is_ipv4 ipv4 or ipv6
1442 * @param src_addr source address
1443 * @param dst_addr destination address
1444 * @param tcp_header tcp header pointer
1445 * @param tcp_len tcp length
1446 */
1447kal_uint16 ipc_calc_tcp_checksum(kal_bool is_ipv4,
1448 kal_uint8 *src_addr,
1449 kal_uint8 *dst_addr,
1450 kal_uint8 *tcp_header,
1451 kal_uint32 tcp_len);
1452
1453/**
1454 * calculate UDP checksum
1455 *
1456 * @param is_ipv4 ipv4 or ipv6
1457 * @param src_addr source address
1458 * @param dst_addr destination address
1459 * @param udp_header udp header pointer
1460 * @param udp_len udp length
1461 */
1462kal_uint16 ipc_calc_udp_checksum(kal_bool is_ipv4,
1463 kal_uint8 *src_addr,
1464 kal_uint8 *dst_addr,
1465 kal_uint8 *udp_header,
1466 kal_uint32 udp_len);
1467
1468/**
1469 * calculate IPv4 checksum
1470 *
1471 * @param ip_header IP header pointer
1472 */
1473kal_uint16 ipc_calc_ipv4_checksum(kal_uint8 *ip_header);
1474
1475/**
1476 * send DL did by channel_id
1477 *
1478 * @param net_type network type
1479 * @param ch_id channel id
1480 * @param p_did_head did head
1481 * @param p_did_tail did tail
1482 */
1483kal_bool ipc_send_dl_did_by_ch_id(kal_uint8 net_type,
1484 kal_uint8 ch_id,
1485 upcm_did *p_did_head,
1486 upcm_did *p_did_tail);
1487
1488
1489/**
1490 * Send datagram in QBM GPD to the netowrk interface after unwinding call stack
1491 *
1492 * @param pkt Packet GPD
1493 * @param netif_id Network interface ID.
1494 * @param session_type IPV4/V6 session type
1495 */
1496kal_bool ipc_send_dl_pkt_enqueue(qbm_gpd *pkt, kal_uint32 netif_id, kal_uint32 session_type);
1497
1498/**
1499 * register ipc filter
1500 *
1501 * @param data_path_direction DL_DATA_PATH or UL_DATA_PATH
1502 * @param p_rules filter rules
1503 * @param p_ntfy_ctxt filter match notification context
1504 *
1505 * @return non negative filter id for successful, otherwise IPC_INVALID_FILTER_ID
1506 */
1507kal_int32 ipc_reg_filter(ipc_data_path_direction_e data_path_direct,
1508 ipc_filter_rules_t *p_rules,
1509 ipc_filter_ntfy_ctxt_t *p_ntfy_ctxt);
1510
1511/**
1512 * deregister ipc filter
1513 *
1514 * @param filter_id the filter_id which want to be deregistered
1515 *
1516 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
1517 */
1518kal_bool ipc_dereg_filter(kal_int32 filter_id);
1519
1520/**
1521 * Get data usage by Netif_id
1522 *
1523 * @param netif_id [IN] the netif_id for which want to know data usgae
1524 * @param data_usage [OUT] data usage of uplink and downlink path
1525 *
1526 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
1527 */
1528kal_bool ipc_get_data_usage_by_netif_id(kal_uint32 netif_id, ipc_data_usage_info_t *data_usage);
1529
1530/**
1531 * Get data usage by pdn_id
1532 *
1533 * @param pdn_id [IN] the pdn_id for which want to know data usgae
1534 * @param proto_idx [IN] the sim_idx for which want to know data usgae
1535 * @param data_usage [OUT] data usage of uplink and downlink path
1536 *
1537 * @return KAL_TRUE if successful, KAL_FALSE otherwise.
1538 */
1539kal_bool ipc_get_data_usage_by_pdn_id(kal_uint32 pdn_id, kal_uint8 proto_idx, ipc_data_usage_info_t *data_usage);
1540
1541#endif /* __INC_IPC_API_H */