-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcapi20.h
4880 lines (4185 loc) · 137 KB
/
capi20.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-
* Copyright (c) 2002-2005 Thomas Wintergerst. All rights reserved.
*
* Copyright (c) 2005-2006 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* capi20.h - definition of CAPI messages
* --------------------------------------
*
* See "http://www.capi.org/" for a more detailed description
* of the messages.
*
* This file uses alot of macros which can be expanded with
* "cpp capi20.h | sed -e 'y/;/\n/' | more".
*
* All structures which name ends with *ENCODED
* use little endian byte order.
*
* All structures which name ends with *DECODED
* use host byte order.
*
* $FreeBSD: $
*
*/
#ifndef _CAPI20_H_
#define _CAPI20_H_
#include <sys/cdefs.h>
#include <sys/endian.h>
#if !defined(_KERNEL)
#include <stdint.h>
#endif
#ifndef __packed
#define __packed __attribute__((__packed__))
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __UA_TYPES_H__
#define __UA_TYPES_H__
/* the following structures are
* used to force the compiler to
* generate un-aligned memory
* access code on processors that
* do not support un-aligned
* memory accesses:
*/
struct void_p {
void *data;
} __packed;
struct uint16_p {
uint16_t data;
} __packed;
struct uint32_p {
uint32_t data;
} __packed;
struct uint64_p {
uint64_t data;
} __packed;
typedef struct void_p void_p_t;
typedef struct uint16_p uint16_p_t;
typedef struct uint32_p uint32_p_t;
typedef struct uint64_p uint64_p_t;
#endif
/* global defines */
#define CAPI_STACK_VERSION 213
#define CAPI_APPLICATION_MAX 0x80 /* units */
#define CAPI_DEVICE_NAME "/dev/capi20"
#define CAPI_SHLIB_BASENAME "libcapi20.so"
/*---------------------------------------------------------------------------*
* macros
*---------------------------------------------------------------------------*/
#ifndef NOT
#define NOT(arg) _NOT(YES arg(() NO))
#define _NOT(args...) args
#endif
#ifndef YES
#define YES(args...) args
#define NO(args...)
#endif
#ifndef END
#define END(args...) args
#endif
#if ((1-YES(1)) || (1-NOT(NO)(1)) NO(||1))
#error "macros are not expanded correctly"
#endif
#ifndef ADD_BYTES
#define ADD_BYTES(ptr,size) ((void *)(((uint8_t *)(ptr)) + (size)))
#endif
/* information element types
* for internal use:
*/
#define IE_END 0
#define IE_BYTE 1
#define IE_WORD 2
#define IE_DWORD 3
#define IE_QWORD 4
#define IE_STRUCT 5 /* excludes length field */
#define IE_STRUCT_CAPI 6 /* includes length field */
#define IE_STRUCT_DECODED 7
#define IE_STRUCT_DECODED_EMPTY 8
#define IE_BYTE_ARRAY 9
#define IE_MAX 10 /* exclusive */
enum {
CAPI_COMPOSE = IE_STRUCT_DECODED,
CAPI_DEFAULT = IE_STRUCT_DECODED_EMPTY
};
struct capi_struct {
uint16_t len;
uint8_t * ppbyte[0]; /* casting hack */
void * ptr;
} __packed;
#define IE_BYTE_COMPILE_M(b,w,d,q,s,a) b
#define IE_BYTE_COMPILE_1(name, def, decode) \
decode(uint8_t name##_BYTE;) \
uint8_t name;
#define IE_WORD_COMPILE_M(b,w,d,q,s,a) w
#define IE_WORD_COMPILE_1(name, def, decode) \
decode(uint8_t name##_WORD;) \
uint16_t name;
#define IE_DWORD_COMPILE_M(b,w,d,q,s,a) d
#define IE_DWORD_COMPILE_1(name, def, decode) \
decode(uint8_t name##_DWORD;) \
uint32_t name;
#define IE_QWORD_COMPILE_M(b,w,d,q,s,a) q
#define IE_QWORD_COMPILE_1(name, def, decode) \
decode(uint8_t name##_QWORD;) \
uint64_t name;
#define IE_STRUCT_COMPILE_M(b,w,d,q,s,a) s
#define IE_STRUCT_COMPILE_1(name, def, decode) \
decode(uint8_t name##_STRUCT; \
struct capi_struct name;) \
NOT(decode)(/* structure length is set to \
* zero. Use the *DECODED \
* structure if length is non- \
* zero. \
*/ \
uint8_t name##_Null;)
#define IE_BYTE_ARRAY_COMPILE_M(b,w,d,q,s,a) a
#define IE_BYTE_ARRAY_COMPILE_1(name, def, decode) \
decode(uint8_t name##_BYTE_ARRAY; \
uint16_t name##_BYTE_ARRAY_LENGTH; ) \
uint8_t name [def];
#define CAPI_MAKE_DECODED_FIELD(n, type, field, def) \
IE_##type##_COMPILE_1(field, def, YES)
#define CAPI_MAKE_ENCODED_FIELD(n, type, field, def) \
IE_##type##_COMPILE_1(field, def, NO)
#define CAPI_MAKE_STRUCT(name) \
struct name##_DECODED { \
name(CAPI_MAKE_DECODED_FIELD,)() \
uint8_t name##_end; \
} __packed; \
struct name##_ENCODED { \
name(CAPI_MAKE_ENCODED_FIELD,)() \
} __packed;
#define CAPI_MAKE_DEF_1(n,ENUM,value) \
enum { CAPI_##ENUM = (value) }; \
CAPI_MAKE_STRUCT(CAPI_##ENUM##_REQ) \
CAPI_MAKE_STRUCT(CAPI_##ENUM##_CONF) \
CAPI_MAKE_STRUCT(CAPI_##ENUM##_IND) \
CAPI_MAKE_STRUCT(CAPI_##ENUM##_RESP)
#define CAPI_MAKE_DEF_2(n,ENUM,value) \
CAPI_##ENUM##_INDEX,
#define CAPI_MAKE_DEF_3(n, ENUM) \
CAPI_MAKE_STRUCT(CAPI_##ENUM)
#define CAPI_MAKE_UNION_1(n,ENUM,value) \
struct CAPI_##ENUM##_REQ_##n ENUM##_REQ; \
struct CAPI_##ENUM##_CONF_##n ENUM##_CONF; \
struct CAPI_##ENUM##_IND_##n ENUM##_IND; \
struct CAPI_##ENUM##_RESP_##n ENUM##_RESP;
#define CAPI_MAKE_UNION_2(n, ENUM) \
struct CAPI_##ENUM##_##n ENUM;
#define CAPI_DEBUG_OFFSET_1(field) \
(((uint8_t *)&(((struct capi_message_decoded *)0)->field)) - ((uint8_t *)0))
/* this macro is a copy of the
* next macro and is used to
* allow macro recursion
*/
#define CAPI_MAKE_DEBUG_3(n, type, field, def) \
IE_##type##_COMPILE_M \
( \
YES({ IE_BYTE, 1, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
YES({ IE_WORD, 2, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
YES({ IE_DWORD, 4, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
YES({ IE_QWORD, 8, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
CAPI_##def(NO,) \
( \
CAPI_##def(CAPI_MAKE_DEBUG_3, def)() \
) \
NOT(CAPI_##def(NO,)) \
( \
{ IE_STRUCT, sizeof(void *), \
CAPI_DEBUG_OFFSET_1(n.field.ptr), #field ".ptr" }, \
) \
, \
YES({ IE_BYTE_ARRAY, sizeof(uint8_t [def]), \
CAPI_DEBUG_OFFSET_1(n.field), #field "[" #def "]"},) \
)
/* this macro is used to make the debug
* table in "libcapi.c"
*/
#define CAPI_MAKE_DEBUG_2(n, type, field, def) \
IE_##type##_COMPILE_M \
( \
YES({ IE_BYTE, 1, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
YES({ IE_WORD, 2, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
YES({ IE_DWORD, 4, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
YES({ IE_QWORD, 8, CAPI_DEBUG_OFFSET_1(n.field), #field },) \
, \
CAPI_##def(NO,) \
( \
CAPI_##def(CAPI_MAKE_DEBUG_3, def)() \
) \
NOT(CAPI_##def(NO,)) \
( \
{ IE_STRUCT, sizeof(void *), \
CAPI_DEBUG_OFFSET_1(n.field.ptr), #field ".ptr" }, \
) \
, \
YES({ IE_BYTE_ARRAY, sizeof(uint8_t [def]), \
CAPI_DEBUG_OFFSET_1(n.field), #field "[" #def "]"},) \
)
#define CAPI_MAKE_DEBUG_1(n, ENUM, value) \
{ IE_END, CAPI_P_REQ(ENUM), CAPI_REQ(ENUM), "CAPI_" #ENUM "_REQ" }, \
CAPI_##ENUM##_REQ (CAPI_MAKE_DEBUG_2, data.ENUM##_REQ )() \
{ IE_END, CAPI_P_CONF(ENUM), CAPI_CONF(ENUM), "CAPI_" #ENUM "_CONF" }, \
CAPI_##ENUM##_CONF(CAPI_MAKE_DEBUG_2, data.ENUM##_CONF)() \
{ IE_END, CAPI_P_IND(ENUM), CAPI_IND(ENUM), "CAPI_" #ENUM "_IND" }, \
CAPI_##ENUM##_IND (CAPI_MAKE_DEBUG_2, data.ENUM##_IND )() \
{ IE_END, CAPI_P_RESP(ENUM), CAPI_RESP(ENUM), "CAPI_" #ENUM "_RESP" }, \
CAPI_##ENUM##_RESP(CAPI_MAKE_DEBUG_2, data.ENUM##_RESP)()
#define CAPI_MAKE_CASES(n, ENUM, value) \
case CAPI_P_REQ(ENUM): \
CAPI_INIT_2(CAPI_##ENUM##_REQ,&((n)->data.ENUM##_REQ)) \
break; \
case CAPI_P_CONF(ENUM): \
CAPI_INIT_2(CAPI_##ENUM##_CONF,&((n)->data.ENUM##_CONF)) \
break; \
case CAPI_P_IND(ENUM): \
CAPI_INIT_2(CAPI_##ENUM##_IND,&((n)->data.ENUM##_IND)) \
break; \
case CAPI_P_RESP(ENUM): \
CAPI_INIT_2(CAPI_##ENUM##_RESP,&((n)->data.ENUM##_RESP)) \
break;
#define CAPI_(m,n) NO /* invalid structure */
#define CAPI_MAKE_INIT_1(n, type, field, def) \
(n)->field##_##type = IE_##type; \
IE_##type##_COMPILE_M \
(,,,,,(n)->field##_##type##_LENGTH = sizeof(uint8_t [def]);)
#if (IE_STRUCT_DECODED_EMPTY == 0)
#error "IE_STRUCT_DECODED_EMPTY cannot be zero"
#endif
#define CAPI_MAKE_INIT_2(n, type, field, def) \
IE_##type##_COMPILE_M \
( \
/* BYTE */ \
(n)->field##_##type = IE_##type; \
, \
/* WORD */ \
(n)->field##_##type = IE_##type; \
, \
/* DWORD */ \
(n)->field##_##type = IE_##type; \
, \
/* QWORD */ \
(n)->field##_##type = IE_##type; \
, \
/* STRUCT */ \
CAPI_##def(NO,) \
( \
/* allow the application to set type */ \
if((n)->field##_##type != IE_STRUCT_DECODED_EMPTY) \
{ (n)->field##_##type = IE_STRUCT_DECODED; } \
\
/* use hints set by the environment to \
* setup the *DECODED pointer and structure \
*/ \
(n)->field.ptr = &def##_STRUCT; \
def##_INIT = 1; \
) \
NOT(CAPI_##def(NO,)) \
( \
/* standard CAPI structure pointer */ \
(n)->field##_##type = IE_##type##_CAPI; \
) \
, \
/* BYTE ARRAY */ \
(n)->field##_##type = IE_##type; \
(n)->field##_##type##_LENGTH = sizeof(uint8_t [def]); \
)
/* this macro is used to initialize
* the *DECODED structures before
* passed to "capi_encode()" or
* "capi_decode()"
*/
#define CAPI_INIT(what, ptr) \
{ what(CAPI_MAKE_INIT_1,ptr)(); \
(ptr)->what##_end = IE_END; } \
/**/
/* internal use macro */
#define CAPI_INIT_2(what, ptr) \
{ what(CAPI_MAKE_INIT_2,ptr)(); \
(ptr)->what##_end = IE_END; } \
/**/
/*---------------------------------------------------------------------------*
* definition of CAPI commands
*---------------------------------------------------------------------------*/
/* CAPI sub commands */
enum {
CAPI_REQ = 0x80,
CAPI_CONF = 0x81,
CAPI_IND = 0x82,
CAPI_RESP = 0x83,
CAPI_PACKED = 0x84 /* non-standard */
};
/* CAPI commands
*
* (the enums are generated later
* and will look like CAPI_XXX = value)
*/
#if 1
#define CAPI_COMMANDS(m,n) \
/*m(n, enum , value )* \
*m(n,------------------------------,-------)*/ \
m(n, DATA_B3 , 0x0086) \
m(n, CONNECT , 0x0002) \
m(n, CONNECT_ACTIVE , 0x0003) \
m(n, CONNECT_B3 , 0x0082) \
m(n, CONNECT_B3_ACTIVE , 0x0083) \
m(n, CONNECT_B3_T90_ACTIVE , 0x0088) \
m(n, DISCONNECT , 0x0004) \
m(n, DISCONNECT_B3 , 0x0084) \
m(n, ALERT , 0x0001) \
m(n, INFO , 0x0008) \
m(n, SELECT_B_PROTOCOL , 0x0041) \
m(n, FACILITY , 0x0080) \
m(n, RESET_B3 , 0x0087) \
m(n, MANUFACTURER , 0x00FF) \
m(n, LISTEN , 0x0005) \
/**/
#else
#define CAPI_COMMANDS(m,n) \
/*m(n, enum , value )* \
*m(n,------------------------------,-------)*/ \
m(n, ALERT , 0x0001) \
m(n, CONNECT , 0x0002) \
m(n, CONNECT_ACTIVE , 0x0003) \
m(n, DISCONNECT , 0x0004) \
m(n, LISTEN , 0x0005) \
m(n, INFO , 0x0008) \
m(n, SELECT_B_PROTOCOL , 0x0041) \
m(n, FACILITY , 0x0080) \
m(n, CONNECT_B3 , 0x0082) \
m(n, CONNECT_B3_ACTIVE , 0x0083) \
m(n, DISCONNECT_B3 , 0x0084) \
m(n, DATA_B3 , 0x0086) \
m(n, RESET_B3 , 0x0087) \
m(n, CONNECT_B3_T90_ACTIVE , 0x0088) \
m(n, MANUFACTURER , 0x00FF) \
/**/
#warning "CAPI commands sorted by value"
#endif
/*
* Format of a standard CAPI command:
*
* MSB LSB
* +--------------------+--------------------+
* | sub-command 8-bits | command 8-bits |
* +--------------------+--------------------+
* | CAPI_REQ, CAPI_IND | e.g. CAPI_DATA_B3 |
* | CAPI_CONF, | |
* | CAPI_RESP | |
* +--------------------+--------------------+
*
*
* Format of a packed CAPI command:
*
* MSB LSB
* +---------------+------------+---------+----------------------+
* | sub-command | originator | command | question or answer |
* | 8-bit | 1-bit | 6-bit | 1-bit |
* +---------------+------------+---------+----------------------+
* | CAPI_PACKED | appl.: 0 | | question: 0 (IND/REQ)|
* | | kernel: 1 | | answer: 1 (CONF/RESP)|
* +---------------+------------+---------+----------------------+
*
*/
/* CAPI command generators
*
* example:
*
* if(cmd == CAPI_REQ(DATA_B3))
* ...
*/
/* standard version */
#if !defined(_KERNEL)
#define CAPI_REQ(cmd) ((CAPI_##cmd)|(CAPI_REQ << 8))
#define CAPI_RESP(cmd) ((CAPI_##cmd)|(CAPI_RESP << 8))
#endif
#define CAPI_CONF(cmd) ((CAPI_##cmd)|(CAPI_CONF << 8))
#define CAPI_IND(cmd) ((CAPI_##cmd)|(CAPI_IND << 8))
/* packed version */
#define CAPI_P_REQ(cmd) ((CAPI_##cmd##_INDEX << 1)^(CAPI_PACKED << 8)^0x7e)
#define CAPI_P_CONF(cmd) ((CAPI_##cmd##_INDEX << 1)^(CAPI_PACKED << 8)^0x81)
#define CAPI_P_IND(cmd) ((CAPI_##cmd##_INDEX << 1)^(CAPI_PACKED << 8)^0x80)
#define CAPI_P_RESP(cmd) ((CAPI_##cmd##_INDEX << 1)^(CAPI_PACKED << 8)^0x7f)
#define CAPI_P_MIN (((CAPI_COMMAND_INDEX_MAX-1) << 1)^(CAPI_PACKED << 8)^0x7e) /* inclusive */
#define CAPI_P_MAX ( (CAPI_COMMAND_INDEX_MAX << 1)^(CAPI_PACKED << 8)^0x80) /* exclusive */
#define __CAPI_COMMAND_PACK(n, ENUM, value) \
((n) == (value)) ? ((CAPI_##ENUM##_INDEX) << 1) :
/* this macro takes any command and outputs a
* packed CAPI command (which is better suited
* for switching)
*/
#define CAPI_COMMAND_PACK(cmd) \
((((cmd) >> 8) == CAPI_PACKED) ? (cmd) : \
((((cmd) >> 8) == CAPI_REQ) ? ((CAPI_PACKED << 8)^0x7e) : \
(((cmd) >> 8) == CAPI_CONF) ? ((CAPI_PACKED << 8)^0x81) : \
(((cmd) >> 8) == CAPI_IND) ? ((CAPI_PACKED << 8)^0x80) : \
(((cmd) >> 8) == CAPI_RESP) ? ((CAPI_PACKED << 8)^0x7f) : \
0) ^ \
(CAPI_COMMANDS(__CAPI_COMMAND_PACK, (cmd) & 0xFF) 0x7e))
/*---------------------------------------------------------------------------*
* definition of CAPI messages and substructures
*
* All CAPI messages and substructures are declared like macros. One
* reason for this, is to make future updating easier. When there is a
* new element added to a message, one simply adds a line to a macro,
* and then all translation tables and structures are updated at the
* next compile. Another reason is that the CAPI messages contain
* dynamic elements. For example the "STRUCT" element can have a size
* from 0 to 65535 bytes inclusivly. The problem is that the offset to
* the elements from the start of the message, then becomes a
* variable, and then classical "struct { } name;" definitions cannot
* be used.
*
* The structure definition macros should use the following format:
*
* #define CUSTOM(m,n) \
* m(n, type, field, def)\
* m(n, type, field, def)\
* END
*
* Description of the parameters passed to the "m" macro:
*
* ---------+--------------------------------------------------
* n | second argument passed to parent macro
* ---------+--------------------------------------------------
* type | BYTE, WORD, DWORD, QWORD, STRUCT or BYTE_ARRAY
* ---------+--------------------------------------------------
* field | choose an appropriate name for this field
* ---------+--------------------------------------------------
* def | If type is STRUCT, this field is prefixed by
* | "CAPI_" to get the structure definition macro.
* | The default is to leave this field empty. This
* | field does not affect structure generation, but
* | is only used when generating
* | the "struct capi_message_decoded" translator.
* | When this field is non-empty the translator
* | will decode the STRUCT using the definition,
* | before proceeding with the next information
* | element. The pointer to the *DECODED structure,
* | where the STRUCT should be decoded, is passed
* | indirectly using variables which name are
* | "CAPI_"field"_INIT" and "CAPI_"field"_STRUCT".
* |
* | If type is BYTE_ARRAY, this field specifices
* | the array size: 0, 1, 2 ... N
* |
* | Else this field has no effect.
* ---------+--------------------------------------------------
*
* Here is an example on how to use the "CUSTOM" macro:
*
* CAPI_MAKE_STRUCT(CUSTOM);
*
* struct CUSTOM_DECODED custom = { 0 };
*
* uint16_t len;
*
* uint8_t buffer[256];
*
* CAPI_INIT(CUSTOM, &custom);
*
* custom.xxx = xxx;
*
* len = capi_encode(&buffer, sizeof(buffer), &custom);
*
* ...
*
* capi_decode(&buffer, len, &custom);
*
*---------------------------------------------------------------------------*/
#define CAPI_HEADER(m,n) \
m(n, WORD , wLen,)\
m(n, WORD , wApp,)\
m(n, WORD , wCmd,)\
m(n, WORD , wNum,)\
m(n, DWORD , dwCid,)\
END
/* unused CID value */
#define CAPI_CID_UNUSED 0
/* masks for "dwCid" */
#define CAPI_CIDMASK_CTLR 0x0000007FUL
#define CAPI_CIDMASK_CTLR_TYPE 0x00000080UL
#define CAPI_CIDMASK_PLCI 0x0000FF00UL
#define CAPI_CIDMASK_NCCI 0xFFFF0000UL
#define CAPI_CIDSHIFT_PLCI 8
#define CAPI_CIDSHIFT_NCCI 16
/* extract the controller from a CID */
#define CAPI_GET_CTLR_FROM_CID(dwCid) \
((dwCid) & CAPI_CIDMASK_CTLR)
/* extract the PLCI from a CID */
#define CAPI_GET_PLCI_FROM_CID(dwCid) \
(((dwCid) & CAPI_CIDMASK_PLCI) >> CAPI_CIDSHIFT_PLCI)
/* extract the NCCI from a CID */
#define CAPI_GET_NCCI_FROM_CID(dwCid) \
(((dwCid) & CAPI_CIDMASK_NCCI) >> CAPI_CIDSHIFT_NCCI)
CAPI_MAKE_STRUCT(CAPI_HEADER);
/* ================================================ */
#define CAPI_ALERT_REQ(m,n) \
m(n, STRUCT, add_info, ADDITIONAL_INFO)\
END
#define CAPI_ALERT_CONF(m,n) \
m(n, WORD, wInfo,)\
END
#define CAPI_ALERT_IND(m,n) \
END /* not used */
#define CAPI_ALERT_RESP(m,n) \
END /* not used */
/* ================================================ */
#define CAPI_CONNECT_REQ(m,n) \
m(n, WORD , wCIP,)\
m(n, STRUCT, dst_telno,)\
m(n, STRUCT, src_telno,)\
m(n, STRUCT, dst_subaddr,)\
m(n, STRUCT, src_subaddr,)\
m(n, STRUCT, b_protocol, B_PROTOCOL)\
m(n, STRUCT, BC,)\
m(n, STRUCT, LLC,)\
m(n, STRUCT, HLC,)\
m(n, STRUCT, add_info, ADDITIONAL_INFO)\
m(n, BYTE, bFlag_0,) /* BSD specific */\
m(n, STRUCT, src_telno_2,) /* BSD specific */\
m(n, STRUCT, display,) /* BSD specific */\
END
#define CAPI_CONNECT_CONF(m,n) \
m(n, WORD , wInfo,)\
END
#define CAPI_CONNECT_IND(m,n) \
m(n, WORD , wCIP,)\
m(n, STRUCT, dst_telno,)\
m(n, STRUCT, src_telno,)\
m(n, STRUCT, dst_subaddr,)\
m(n, STRUCT, src_subaddr,)\
m(n, STRUCT, BC,)\
m(n, STRUCT, LLC,)\
m(n, STRUCT, HLC,)\
m(n, STRUCT, add_info, ADDITIONAL_INFO)\
m(n, STRUCT, src_telno_2,)\
m(n, STRUCT, display,) /* BSD specific */\
m(n, BYTE, bFlag_1,) /* BSD specific */\
END
#define CAPI_CONNECT_RESP(m,n) \
m(n, WORD , wReject,)\
m(n, STRUCT, b_protocol, B_PROTOCOL)\
m(n, STRUCT, dst_telno,)\
m(n, STRUCT, dst_subaddr,)\
m(n, STRUCT, LLC,)\
m(n, STRUCT, add_info, ADDITIONAL_INFO)\
m(n, STRUCT, date_time,) /* BSD specific */\
END
/* definition of "wReject": */
#define CAPI_CALL_ACCEPT 0
#define CAPI_CALL_IGNORE 1
#define CAPI_CALL_REJECT_NORMAL_CLEARING 2
#define CAPI_CALL_REJECT_USER_BUSY 3
#define CAPI_CALL_REJECT_NO_CHANNEL 4
#define CAPI_CALL_REJECT_FACILITY 5
#define CAPI_CALL_REJECT_CHANNEL_UNACCEPTABLE 6
#define CAPI_CALL_REJECT_INCOMPAT_DESTINATION 7
#define CAPI_CALL_REJECT_OUT_OF_ORDER 8
/* definition of "wCIP": */
#define CAPI_CIP_NO 0
#define CAPI_CIP_SPEECH 1
#define CAPI_CIP_UNRESTRICTED_DATA 2
#define CAPI_CIP_RESTRICTED_DATA 3
#define CAPI_CIP_3100Hz_AUDIO 4
#define CAPI_CIP_7kHz_AUDIO 5
#define CAPI_CIP_VIDEO 6
#define CAPI_CIP_PACKET_MODE 7
#define CAPI_CIP_DATA_56 8
#define CAPI_CIP_UNRESTRICTED_DATA_TONES 9
#define CAPI_CIP_TELEPHONY 16
#define CAPI_CIP_FAX_G2_G3 17
#define CAPI_CIP_FAX_G4_CLASS1 18
#define CAPI_CIP_TELETEX_BASIC_MIXED 19
#define CAPI_CIP_FAX_G4_CLASS2_CLASS3 19
#define CAPI_CIP_TELETEX_BASIC_PROCESSABLE 20
#define CAPI_CIP_TELETEX_BASIC 21
#define CAPI_CIP_VIDEOTEX 22
#define CAPI_CIP_TELEX 23
#define CAPI_CIP_X400 24
#define CAPI_CIP_X200 25
#define CAPI_CIP_7kHz_TELEPHONY 26
#define CAPI_CIP_VIDEO_TELEPHONY_1ST 27
#define CAPI_CIP_VIDEO_TELEPHONY_2ND 28
/* definition of "bFlag_0": */
#define CAPI_FLAG0_WANT_LATE_INBAND 0x01
/* definition of "bFlag_1": */
#define CAPI_FLAG1_NOT_END_TO_END_DIGITAL 0x01
/* definition of number type bits in "src_telno" */
#define CAPI_TON_OTHER 0x00
#define CAPI_TON_INTERNAT 0x10
#define CAPI_TON_NATIONAL 0x20
/* definition of presentation bits in "src_telno" */
#define CAPI_PRS_ALLOWED 0x00
#define CAPI_PRS_RESTRICT 0x20
#define CAPI_PRS_NNINTERW 0x40
#define CAPI_PRS_RESERVED 0x60
/* definition of screening bits in "src_telno" */
#define CAPI_SCR_USR_NOSC 0x00
#define CAPI_SCR_USR_PASS 0x01
#define CAPI_SCR_USR_FAIL 0x02
#define CAPI_SCR_NET 0x03
/* ================================================ */
#define CAPI_CONNECT_ACTIVE_IND(m,n) \
m(n, STRUCT, connected_telno,)\
m(n, STRUCT, connected_subaddr,)\
m(n, STRUCT, LLC,)\
m(n, STRUCT, date_time,) /* BSD specific */\
END
#define CAPI_CONNECT_ACTIVE_RESP(m,n) \
END /* empty */
#define CAPI_CONNECT_ACTIVE_REQ(m,n) \
END /* not used */
#define CAPI_CONNECT_ACTIVE_CONF(m,n) \
END /* not used */
/* ================================================ */
#define CAPI_CONNECT_B3_ACTIVE_IND(m,n) \
m(n, STRUCT, NCPI,)\
END
#define CAPI_CONNECT_B3_ACTIVE_RESP(m,n) \
END /* empty */
#define CAPI_CONNECT_B3_ACTIVE_REQ(m,n) \
END /* not used */
#define CAPI_CONNECT_B3_ACTIVE_CONF(m,n) \
END /* not used */
/* ================================================ */
#define CAPI_CONNECT_B3_REQ(m,n) \
m(n, STRUCT, NCPI,)\
END
#define CAPI_CONNECT_B3_CONF(m,n) \
m(n, WORD , wInfo,)\
END
#define CAPI_CONNECT_B3_IND(m,n) \
m(n, STRUCT, NCPI,)\
END
#define CAPI_CONNECT_B3_RESP(m,n) \
m(n, WORD , wReject,)\
m(n, STRUCT, NCPI,)\
END
/* ================================================ */
#define CAPI_CONNECT_B3_T90_ACTIVE_IND(m,n) \
m(n, STRUCT, NCPI,)\
END
#define CAPI_CONNECT_B3_T90_ACTIVE_RESP(m,n) \
END /* empty */
#define CAPI_CONNECT_B3_T90_ACTIVE_REQ(m,n) \
END /* not used */
#define CAPI_CONNECT_B3_T90_ACTIVE_CONF(m,n) \
END /* not used */
/* ================================================ */
#define CAPI_DATA_B3_REQ(m,n) \
m(n, DWORD , dwPtr_1,)\
m(n, WORD , wLen,)\
m(n, WORD , wHandle,)\
m(n, WORD , wFlags,)\
m(n, QWORD , qwPtr_2,)\
END
#define CAPI_DATA_B3_CONF(m,n) \
m(n, WORD , wHandle,)\
m(n, WORD , wInfo,)\
END
#define CAPI_DATA_B3_IND(m,n) \
m(n, DWORD , dwPtr_1,)\
m(n, WORD , wLen,)\
m(n, WORD , wHandle,)\
m(n, WORD , wFlags,)\
m(n, QWORD , qwPtr_2,)\
END
#define CAPI_DATA_B3_RESP(m,n) \
m(n, WORD , wHandle,)\
END
/* definition of "wFlags": */
#define CAPI_DATA_B3_FLAG_QUALIFIER 0x0001
#define CAPI_DATA_B3_FLAG_MORE_DATA 0x0002
#define CAPI_DATA_B3_FLAG_DELIVERY_CONF 0x0004
#define CAPI_DATA_B3_FLAG_EXPEDITED 0x0008
#define CAPI_DATA_B3_FLAG_UI_FRAME 0x0010
#define CAPI_DATA_B3_FLAG_BREAK 0x0010
#define CAPI_DATA_B3_FLAG_FRAME_ERROR 0x8000
/* NOTES:
* dwPtr_1 is coded 0 if CPU is 64-bit
* qwPtr_2 is coded 0 if CPU is 32-bit
* wHandle is copied from corresponding
* data-b3-request or data-b3-indication.
*/
/* ================================================ */
#define CAPI_DISCONNECT_B3_REQ(m,n) \
m(n, STRUCT, NCPI,)\
END
#define CAPI_DISCONNECT_B3_CONF(m,n) \
m(n, WORD , wInfo,)\
END
#define CAPI_DISCONNECT_B3_IND(m,n) \
m(n, WORD , wReason,)\
m(n, STRUCT, NCPI,)\
END
#define CAPI_DISCONNECT_B3_RESP(m,n) \
END /* empty */
/* ================================================ */
#define CAPI_DISCONNECT_REQ(m,n) \
m(n, STRUCT, add_info, ADDITIONAL_INFO)\
END
#define CAPI_DISCONNECT_CONF(m,n) \
m(n, WORD , wInfo,)\
END
#define CAPI_DISCONNECT_IND(m,n) \
m(n, WORD , wReason,)\
END
#define CAPI_DISCONNECT_RESP(m,n) \
END /* empty */
/* ================================================ */
#define CAPI_FACILITY_REQ(m,n) \
m(n, WORD , wSelector,)\
m(n, STRUCT, Param,)\
END
#define CAPI_FACILITY_CONF(m,n) \
m(n, WORD , wInfo,)\
m(n, WORD , wSelector,)\
m(n, STRUCT, Param,)\
END
#define CAPI_FACILITY_IND(m,n) \
m(n, WORD , wSelector,)\
m(n, STRUCT, Param,)\
END
#define CAPI_FACILITY_RESP(m,n) \
m(n, WORD , wSelector,)\
m(n, STRUCT, Param,)\
END
/* definition of "wSelector": */
#define CAPI_FACILITY_SELECTOR_HANDSET 0
#define CAPI_FACILITY_SELECTOR_DTMF 1
#define CAPI_FACILITY_SELECTOR_V42BIS 2
#define CAPI_FACILITY_SELECTOR_SUPPL_SERVICES 3
#define CAPI_FACILITY_SELECTOR_POWER_MNGMNT_WAKEUP 4
#define CAPI_FACILITY_SELECTOR_LINE_INTERCONNECT 5
#define CAPI_FACILITY_SELECTOR_BROADBAND_EXTENSIONS 6
#define CAPI_FACILITY_SELECTOR_CONTROLLER_EVENTS 7
#define CAPI_FACILITY_SELECTOR_ECHO_CANCELLATION 8
/* ================================================ */
#define CAPI_INFO_REQ(m,n) \
m(n, STRUCT, dst_telno,)\
m(n, STRUCT, add_info, ADDITIONAL_INFO)\
END
#define CAPI_INFO_CONF(m,n) \
m(n, WORD , wInfo,)\
END
#define CAPI_INFO_IND(m,n) \
m(n, WORD , wInfoNum,)\
m(n, STRUCT, InfoElement,)\
END
#define CAPI_INFO_RESP(m,n) \
END /* empty */
/* ================================================ */
#define CAPI_LISTEN_REQ(m,n) \
m(n, DWORD , dwInfoMask,)\
m(n, DWORD , dwCipMask1,)\
m(n, DWORD , dwCipMask2,)\
m(n, STRUCT, src_telno,)\
m(n, STRUCT, src_subaddr,)\
END
/* definition of "dwInfoMask": */
#define CAPI_INFO_MASK_NONE 0x00000000UL
#define CAPI_INFO_MASK_CAUSE 0x00000001UL
#define CAPI_INFO_MASK_DATE_TIME 0x00000002UL
#define CAPI_INFO_MASK_DISPLAY 0x00000004UL
#define CAPI_INFO_MASK_USER_USER 0x00000008UL
#define CAPI_INFO_MASK_CALL_PROGRESSION 0x00000010UL
#define CAPI_INFO_MASK_FACILITY 0x00000020UL
#define CAPI_INFO_MASK_CHARGING 0x00000040UL
#define CAPI_INFO_MASK_CALLED_PARTY_NUMBER 0x00000080UL
#define CAPI_INFO_MASK_CHANNEL_ID 0x00000100UL
#define CAPI_INFO_MASK_EARLY_B3_CONNECT 0x00000200UL
#define CAPI_INFO_MASK_REDIRECTION_INFO 0x00000400UL
#define CAPI_INFO_MASK_SENDING_COMPLETE 0x00001000UL
#define CAPI_INFO_MASK_ALL 0x000017FFUL
/* definition of "dwCipMask1": */
#define CAPI_CIP_MASK1_UNLISTEN 0UL
#define CAPI_CIP_MASK1_ANY 1UL
#define CAPI_CIP_MASK1(CIP) (1 << ((CAPI_CIP_##CIP) % 32))
/* definition of "dwCipMask2": */
#define CAPI_CIP_MASK2_UNLISTEN 0UL
#define CAPI_LISTEN_CONF(m,n) \
m(n, WORD , wInfo,)\
END
#define CAPI_LISTEN_IND(m,n) \
END /* not used */
#define CAPI_LISTEN_RESP(m,n) \
END /* not used */
/* ================================================ */
#define CAPI_MANUFACTURER_REQ(m,n) \
m(n, DWORD , dwManuID,)\
m(n, DWORD , dwClass,)\
m(n, DWORD , dwFunction,)\
m(n, STRUCT, ManuData,)\
END
#define CAPI_MANUFACTURER_CONF(m,n) \
m(n, DWORD , dwManuID,)\
m(n, DWORD , dwClass,)\
m(n, DWORD , dwFunction,)\
m(n, STRUCT, ManuData,)\
END
#define CAPI_MANUFACTURER_IND(m,n) \
m(n, DWORD , dwManuID,)\
m(n, DWORD , dwClass,)\
m(n, DWORD , dwFunction,)\
m(n, STRUCT, ManuData,)\
END