3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/uni/unisig_encode.c,v 1.5 2000/01/17 20:49:56 mks Exp $
31 * ATM Forum UNI 3.0/3.1 Signalling Manager
32 * ----------------------------------------
34 * Message formatting module
38 #include <netatm/kern_include.h>
40 #include <netatm/uni/unisig_var.h>
41 #include <netatm/uni/unisig_msg.h>
42 #include <netatm/uni/unisig_mbuf.h>
43 #include <netatm/uni/unisig_decode.h>
46 __RCSID("@(#) $FreeBSD: src/sys/netatm/uni/unisig_encode.c,v 1.5 2000/01/17 20:49:56 mks Exp $");
53 static int usf_enc_ie __P((struct usfmt *, struct ie_generic *));
54 static int usf_enc_ie_aalp __P((struct usfmt *, struct ie_generic *));
55 static int usf_enc_ie_clrt __P((struct usfmt *, struct ie_generic *));
56 static int usf_enc_ie_bbcp __P((struct usfmt *, struct ie_generic *));
57 static int usf_enc_ie_bhli __P((struct usfmt *, struct ie_generic *));
58 static int usf_enc_ie_blli __P((struct usfmt *, struct ie_generic *));
59 static int usf_enc_ie_clst __P((struct usfmt *, struct ie_generic *));
60 static int usf_enc_ie_cdad __P((struct usfmt *, struct ie_generic *));
61 static int usf_enc_ie_cdsa __P((struct usfmt *, struct ie_generic *));
62 static int usf_enc_ie_cgad __P((struct usfmt *, struct ie_generic *));
63 static int usf_enc_ie_cgsa __P((struct usfmt *, struct ie_generic *));
64 static int usf_enc_ie_caus __P((struct usfmt *, struct ie_generic *));
65 static int usf_enc_ie_cnid __P((struct usfmt *, struct ie_generic *));
66 static int usf_enc_ie_qosp __P((struct usfmt *, struct ie_generic *));
67 static int usf_enc_ie_brpi __P((struct usfmt *, struct ie_generic *));
68 static int usf_enc_ie_rsti __P((struct usfmt *, struct ie_generic *));
69 static int usf_enc_ie_bsdc __P((struct usfmt *, struct ie_generic *));
70 static int usf_enc_ie_trnt __P((struct usfmt *, struct ie_generic *));
71 static int usf_enc_ie_uimp __P((struct usfmt *, struct ie_generic *));
72 static int usf_enc_ie_ident __P((struct usfmt *, struct ie_generic *,
73 struct ie_decode_tbl *));
74 static int usf_enc_atm_addr __P((struct usfmt *, Atm_addr *));
81 u_char ident; /* IE identifier */
82 int (*encode) __P((struct usfmt *, struct ie_generic *));
83 /* Encoding function */
85 { UNI_IE_AALP, usf_enc_ie_aalp },
86 { UNI_IE_CLRT, usf_enc_ie_clrt },
87 { UNI_IE_BBCP, usf_enc_ie_bbcp },
88 { UNI_IE_BHLI, usf_enc_ie_bhli },
89 { UNI_IE_BLLI, usf_enc_ie_blli },
90 { UNI_IE_CLST, usf_enc_ie_clst },
91 { UNI_IE_CDAD, usf_enc_ie_cdad },
92 { UNI_IE_CDSA, usf_enc_ie_cdsa },
93 { UNI_IE_CGAD, usf_enc_ie_cgad },
94 { UNI_IE_CGSA, usf_enc_ie_cgsa },
95 { UNI_IE_CAUS, usf_enc_ie_caus },
96 { UNI_IE_CNID, usf_enc_ie_cnid },
97 { UNI_IE_QOSP, usf_enc_ie_qosp },
98 { UNI_IE_BRPI, usf_enc_ie_brpi },
99 { UNI_IE_RSTI, usf_enc_ie_rsti },
100 { UNI_IE_BLSH, usf_enc_ie_uimp },
101 { UNI_IE_BNSH, usf_enc_ie_uimp },
102 { UNI_IE_BSDC, usf_enc_ie_bsdc },
103 { UNI_IE_TRNT, usf_enc_ie_trnt },
104 { UNI_IE_EPRF, usf_enc_ie_uimp },
105 { UNI_IE_EPST, usf_enc_ie_uimp },
109 extern struct ie_decode_tbl ie_aal1_tbl[];
110 extern struct ie_decode_tbl ie_aal4_tbl_30[];
111 extern struct ie_decode_tbl ie_aal4_tbl_31[];
112 extern struct ie_decode_tbl ie_aal5_tbl_30[];
113 extern struct ie_decode_tbl ie_aal5_tbl_31[];
114 extern struct ie_decode_tbl ie_clrt_tbl[];
118 * Encode a UNI signalling message
121 * usf pointer to a unisig formatting structure
122 * msg pointer to a signalling message structure
126 * errno error encountered
130 usf_enc_msg(usf, msg)
132 struct unisig_msg *msg;
137 struct ie_generic *ie;
141 u_char sb[sizeof(short)];
144 ATM_DEBUG2("usf_enc_msg: usf=%p, msg=%p\n",
148 * Encode the protocol discriminator
150 c = UNI_MSG_DISC_Q93B;
151 rc = usf_byte(usf, &c);
156 * Encode the call reference length
159 rc = usf_byte(usf, &c);
164 * Encode the call reference
166 rc = usf_int3(usf, &msg->msg_call_ref);
171 * Encode the message type
173 rc = usf_byte(usf, &msg->msg_type);
178 * Encode the message type extension
180 c = ((msg->msg_type_flag & UNI_MSG_TYPE_FLAG_MASK) <<
181 UNI_MSG_TYPE_FLAG_SHIFT) +
182 (msg->msg_type_action & UNI_MSG_TYPE_ACT_MASK) +
184 rc = usf_byte(usf, &c);
189 * Save the location of the message length and encode a length
190 * of zero for now. We'll fix the length up at the end.
193 rc = usf_byte_mark(usf, &su.sb[sizeof(short)-2], &lp0);
196 rc = usf_byte_mark(usf, &su.sb[sizeof(short)-1], &lp1);
201 * Process information elements
204 for (i=0; i<UNI_MSG_IE_CNT; i++) {
205 ie = msg->msg_ie_vec[i];
207 rc = usf_enc_ie(usf, ie);
210 len += (ie->ie_length + UNI_IE_HDR_LEN);
216 * Fix the message length in the encoded message
218 su.s = htons((u_short)len);
219 *lp0 = su.sb[sizeof(short)-2];
220 *lp1 = su.sb[sizeof(short)-1];
227 * Encode an information element
230 * usf pointer to a UNISIG formatting structure
231 * msg pointer to a UNISIG message structure
232 * ie pointer to a generic IE structure
236 * errno error encountered
242 struct ie_generic *ie;
250 u_char sb[sizeof(short)];
253 ATM_DEBUG2("usf_enc_ie: usf=%p, ie=%p\n",
257 * Encode the IE identifier
259 rc = usf_byte(usf, &ie->ie_ident);
264 * Encode the extended type
266 c = ((ie->ie_coding & UNI_IE_CODE_MASK) << UNI_IE_CODE_SHIFT) +
267 ((ie->ie_flag & UNI_IE_FLAG_MASK) <<
269 (ie->ie_action & UNI_IE_ACT_MASK) +
271 rc = usf_byte(usf, &c);
276 * Mark the current location in the output stream. Encode a
277 * length of zero for now; we'll come back and fix it up at
281 rc = usf_byte_mark(usf, &su.sb[sizeof(short)-2], &lp0);
284 rc = usf_byte_mark(usf, &su.sb[sizeof(short)-1], &lp1);
289 * Look up the information element in the table
291 for (i=0; (ie->ie_ident != ie_table[i].ident) &&
292 (ie_table[i].encode != NULL); i++) {
294 if (ie_table[i].encode == NULL) {
302 * Process the IE by calling the function indicated
305 rc = ie_table[i].encode(usf, ie);
310 * Set the length in the output stream
312 su.s = htons((u_short)ie->ie_length);
313 *lp0 = su.sb[sizeof(short)-2];
314 *lp1 = su.sb[sizeof(short)-1];
321 * Encode an AAL parameters information element
324 * usf pointer to a unisig formatting structure
325 * ie pointer to an AAL parms IE structure
329 * errno error encountered
333 usf_enc_ie_aalp(usf, ie)
335 struct ie_generic *ie;
339 ATM_DEBUG2("usf_enc_ie_aalp: usf=%p, ie=%p\n",
345 * Encode the AAL type
347 if (ie->ie_aalp_aal_type == T_ATM_ABSENT)
349 rc = usf_byte(usf, &ie->ie_aalp_aal_type);
354 * Process based on AAL type
356 switch (ie->ie_aalp_aal_type) {
357 case UNI_IE_AALP_AT_AAL1:
358 rc = usf_enc_ie_ident(usf, ie, ie_aal1_tbl);
360 case UNI_IE_AALP_AT_AAL3:
361 if (usf->usf_sig->us_proto == ATM_SIG_UNI30)
362 rc = usf_enc_ie_ident(usf, ie, ie_aal4_tbl_30);
364 rc = usf_enc_ie_ident(usf, ie, ie_aal4_tbl_31);
366 case UNI_IE_AALP_AT_AAL5:
367 if (usf->usf_sig->us_proto == ATM_SIG_UNI30)
368 rc = usf_enc_ie_ident(usf, ie, ie_aal5_tbl_30);
370 rc = usf_enc_ie_ident(usf, ie, ie_aal5_tbl_31);
372 case UNI_IE_AALP_AT_AALU:
374 * Encode the user data
377 while (i < sizeof(ie->ie_aalp_user_info)) {
378 rc = usf_byte(usf, &ie->ie_aalp_user_info[i]);
395 * Encode a user cell rate information element
397 * This routine just encodes the parameters required for best
401 * usf pointer to a unisig formatting structure
402 * ie pointer to a cell rate IE structure
406 * errno error encountered
410 usf_enc_ie_clrt(usf, ie)
412 struct ie_generic *ie;
416 ATM_DEBUG2("usf_enc_ie_clrt: usf=%p, ie=%p\n",
421 * Encode Peak Cell Rate Forward CLP = 0 + 1
423 c = UNI_IE_CLRT_FWD_PEAK_01_ID;
424 rc = usf_byte(usf, &c);
427 rc = usf_int3(usf, &ie->ie_clrt_fwd_peak_01);
432 * Encode Peak Cell Rate Backward CLP = 0 + 1
434 c = UNI_IE_CLRT_BKWD_PEAK_01_ID;
435 rc = usf_byte(usf, &c);
438 rc = usf_int3(usf, &ie->ie_clrt_bkwd_peak_01);
443 * Encode Best Effort Flag
445 c = UNI_IE_CLRT_BEST_EFFORT_ID;
446 rc = usf_byte(usf, &c);
457 * Encode the user cell rate IE using the table
460 rc = usf_enc_ie_ident(usf, ie, ie_clrt_tbl);
467 * Encode a broadband bearer capability information element
470 * usf pointer to a unisig formatting structure
471 * ie pointer to a cell rate IE structure
475 * errno error encountered
479 usf_enc_ie_bbcp(usf, ie)
481 struct ie_generic *ie;
486 ATM_DEBUG2("usf_enc_ie_bbcp: usf=%p, ie=%p\n",
492 * Encode the broadband bearer class
494 if (ie->ie_bbcp_bearer_class == T_ATM_ABSENT)
496 c = ie->ie_bbcp_bearer_class & UNI_IE_BBCP_BC_MASK;
497 if (ie->ie_bbcp_bearer_class != UNI_IE_BBCP_BC_BCOB_X)
499 rc = usf_byte(usf, &c);
505 * If the broadband bearer class was X, the next
506 * byte has the traffic type and timing requirements
508 if (ie->ie_bbcp_bearer_class == UNI_IE_BBCP_BC_BCOB_X) {
509 c = ((ie->ie_bbcp_traffic_type & UNI_IE_BBCP_TT_MASK) <<
510 UNI_IE_BBCP_TT_SHIFT) +
511 (ie->ie_bbcp_timing_req &
512 UNI_IE_BBCP_TR_MASK) +
514 rc = usf_byte(usf, &c);
521 * Encode the clipping and user plane connection configuration
523 c = ((ie->ie_bbcp_clipping & UNI_IE_BBCP_SC_MASK) <<
524 UNI_IE_BBCP_SC_SHIFT) +
525 (ie->ie_bbcp_conn_config &
526 UNI_IE_BBCP_CC_MASK) +
528 rc = usf_byte(usf, &c);
538 * Encode a broadband high layer information element
541 * usf pointer to a unisig formatting structure
542 * ie pointer to a cell rate IE structure
546 * errno error encountered
550 usf_enc_ie_bhli(usf, ie)
552 struct ie_generic *ie;
557 ATM_DEBUG2("usf_enc_ie_bhli: usf=%p, ie=%p\n",
563 * Encode the high layer information type
565 if (ie->ie_bhli_type == T_ATM_ABSENT)
567 type = ie->ie_bhli_type | UNI_IE_EXT_BIT;
568 rc = usf_ext(usf, &type);
574 * What comes next depends on the type
576 switch (ie->ie_bhli_type) {
577 case UNI_IE_BHLI_TYPE_ISO:
578 case UNI_IE_BHLI_TYPE_USER:
580 * ISO or user-specified parameters -- take the
581 * length of information from the IE length
583 for (i=0; i<ie->ie_length-1; i++) {
584 rc = usf_byte(usf, &ie->ie_bhli_info[i]);
590 case UNI_IE_BHLI_TYPE_HLP:
592 * Make sure the IE is long enough for the high
593 * layer profile information, then get it
595 if (usf->usf_sig->us_proto != ATM_SIG_UNI30)
597 for (i=0; i<UNI_IE_BHLI_HLP_LEN; i++) {
598 rc = usf_byte(usf, &ie->ie_bhli_info[i]);
604 case UNI_IE_BHLI_TYPE_VSA:
606 * Make sure the IE is long enough for the vendor-
607 * specific application information, then get it
609 for (i=0; i<UNI_IE_BHLI_VSA_LEN; i++) {
610 rc = usf_byte(usf, &ie->ie_bhli_info[i]);
625 * Encode a broadband low layer information element
628 * usf pointer to a unisig formatting structure
629 * ie pointer to a cell rate IE structure
633 * errno error encountered
637 usf_enc_ie_blli(usf, ie)
639 struct ie_generic *ie;
645 ATM_DEBUG2("usf_enc_ie_blli: usf=%p, ie=%p\n",
651 * Encode paramteters for whichever protocol layers the
656 * Layer 1 information
658 if (ie->ie_blli_l1_id && ie->ie_blli_l1_id != T_ATM_ABSENT) {
659 c = (UNI_IE_BLLI_L1_ID << UNI_IE_BLLI_LID_SHIFT) +
661 UNI_IE_BLLI_LP_MASK) +
663 rc = usf_byte(usf, &c);
670 * Layer 2 information
672 if (ie->ie_blli_l2_id && ie->ie_blli_l2_id != T_ATM_ABSENT) {
673 c = (UNI_IE_BLLI_L2_ID << UNI_IE_BLLI_LID_SHIFT) +
675 UNI_IE_BLLI_LP_MASK);
677 switch (ie->ie_blli_l2_id) {
678 case UNI_IE_BLLI_L2P_X25L:
679 case UNI_IE_BLLI_L2P_X25M:
680 case UNI_IE_BLLI_L2P_HDLC1:
681 case UNI_IE_BLLI_L2P_HDLC2:
682 case UNI_IE_BLLI_L2P_HDLC3:
683 case UNI_IE_BLLI_L2P_Q922:
684 case UNI_IE_BLLI_L2P_ISO7776:
686 * Write the Layer 2 type
688 rc = usf_byte(usf, &c);
694 * Encode the Layer 2 mode
696 if (ie->ie_blli_l2_mode) {
697 c = (ie->ie_blli_l2_mode &
698 UNI_IE_BLLI_L2MODE_MASK) <<
699 UNI_IE_BLLI_L2MODE_SHIFT;
700 if (!ie->ie_blli_l2_window)
703 rc = usf_byte(usf, &c);
710 * Encode the Layer 2 window size
712 if (ie->ie_blli_l2_window) {
713 c = (ie->ie_blli_l2_window &
717 rc = usf_byte(usf, &c);
723 case UNI_IE_BLLI_L2P_USER:
725 * Write the Layer 2 type
727 rc = usf_byte(usf, &c);
733 * Encode the user-specified layer 2 info
735 c = (ie->ie_blli_l2_user_proto &
738 rc = usf_byte(usf, &c);
745 * Write the Layer 2 type
748 rc = usf_byte(usf, &c);
757 * Layer 3 information
759 if (ie->ie_blli_l3_id && ie->ie_blli_l3_id != T_ATM_ABSENT) {
761 * Encode the layer 3 protocol ID
763 c = (UNI_IE_BLLI_L3_ID << UNI_IE_BLLI_LID_SHIFT) +
765 UNI_IE_BLLI_LP_MASK);
768 * Process other fields based on protocol ID
770 switch(ie->ie_blli_l3_id) {
771 case UNI_IE_BLLI_L3P_X25:
772 case UNI_IE_BLLI_L3P_ISO8208:
773 case UNI_IE_BLLI_L3P_ISO8878:
775 * Write the protocol ID
777 rc = usf_byte(usf, &c);
782 if (ie->ie_blli_l3_mode ||
783 ie->ie_blli_l3_packet_size ||
784 ie->ie_blli_l3_window) {
785 c = (ie->ie_blli_l3_mode &
786 UNI_IE_BLLI_L3MODE_MASK) <<
787 UNI_IE_BLLI_L3MODE_SHIFT;
788 if (!ie->ie_blli_l3_packet_size &&
789 !ie->ie_blli_l3_window)
792 rc = usf_byte(usf, &c);
798 if (ie->ie_blli_l3_packet_size ||
799 ie->ie_blli_l3_window) {
800 c = ie->ie_blli_l3_packet_size &
801 UNI_IE_BLLI_L3PS_MASK;
802 if (!ie->ie_blli_l3_window)
805 rc = usf_byte(usf, &c);
811 if (ie->ie_blli_l3_window) {
812 c = (ie->ie_blli_l3_window &
816 rc = usf_byte(usf, &c);
822 case UNI_IE_BLLI_L3P_USER:
824 * Write the protocol ID
826 rc = usf_byte(usf, &c);
832 * Encode the user-specified protocol info
834 c = (ie->ie_blli_l3_user_proto &
838 rc = usf_byte(usf, &c);
843 case UNI_IE_BLLI_L3P_ISO9577:
845 * Write the protocol ID
847 rc = usf_byte(usf, &c);
855 ipi = ie->ie_blli_l3_ipi <<
856 UNI_IE_BLLI_L3IPI_SHIFT;
857 rc = usf_ext(usf, &ipi);
862 if (ie->ie_blli_l3_ipi ==
863 UNI_IE_BLLI_L3IPI_SNAP) {
865 rc = usf_byte(usf, &c);
870 &ie->ie_blli_l3_oui[0]);
875 &ie->ie_blli_l3_oui[1]);
880 &ie->ie_blli_l3_oui[2]);
885 &ie->ie_blli_l3_pid[0]);
890 &ie->ie_blli_l3_pid[1]);
899 * Write the layer 3 protocol ID
902 rc = usf_byte(usf, &c);
915 * Encode a call state information element
918 * usf pointer to a unisig formatting structure
919 * ie pointer to a cell rate IE structure
923 * errno error encountered
927 usf_enc_ie_clst(usf, ie)
929 struct ie_generic *ie;
934 ATM_DEBUG2("usf_enc_ie_clst: usf=%p, ie=%p\n",
937 c = ie->ie_clst_state & UNI_IE_CLST_STATE_MASK;
938 rc = usf_byte(usf, &c);
948 * Encode a called party number information element
951 * usf pointer to a unisig formatting structure
952 * ie pointer to a cell rate IE structure
956 * errno error encountered
960 usf_enc_ie_cdad(usf, ie)
962 struct ie_generic *ie;
967 ATM_DEBUG2("usf_enc_ie_cdad: usf=%p, ie=%p\n",
971 * Encode the numbering plan
973 switch(ie->ie_cdad_addr.address_format) {
974 case T_ATM_E164_ADDR:
975 c = UNI_IE_CDAD_PLAN_E164 +
976 (UNI_IE_CDAD_TYPE_INTL
977 << UNI_IE_CDAD_TYPE_SHIFT);
978 ie->ie_length = sizeof(Atm_addr_e164) + 1;
980 case T_ATM_ENDSYS_ADDR:
981 c = UNI_IE_CDAD_PLAN_NSAP +
982 (UNI_IE_CDAD_TYPE_UNK
983 << UNI_IE_CDAD_TYPE_SHIFT);
984 ie->ie_length = sizeof(Atm_addr_nsap) + 1;
990 rc = usf_byte(usf, &c);
995 * Encode the ATM address
997 rc = usf_enc_atm_addr(usf, &ie->ie_cdad_addr);
1004 * Encode a called party subaddress information element
1007 * usf pointer to a unisig formatting structure
1008 * ie pointer to a cell rate IE structure
1012 * errno error encountered
1016 usf_enc_ie_cdsa(usf, ie)
1018 struct ie_generic *ie;
1024 * Encode the subaddress type
1026 switch(ie->ie_cdsa_addr.address_format) {
1027 case T_ATM_ENDSYS_ADDR:
1028 c = UNI_IE_CDSA_TYPE_AESA << UNI_IE_CDSA_TYPE_SHIFT;
1029 ie->ie_length = sizeof(Atm_addr_nsap) + 1;
1034 c |= UNI_IE_EXT_BIT;
1035 rc = usf_byte(usf, &c);
1040 * Encode the ATM address
1042 rc = usf_enc_atm_addr(usf, &ie->ie_cdsa_addr);
1049 * Encode a calling party number information element
1052 * usf pointer to a unisig formatting structure
1053 * ie pointer to a cell rate IE structure
1057 * errno error encountered
1061 usf_enc_ie_cgad(usf, ie)
1063 struct ie_generic *ie;
1068 ATM_DEBUG2("usf_enc_ie_cgad: usf=%p, ie=%p\n",
1072 * Encode the numbering plan
1074 switch(ie->ie_cgad_addr.address_format) {
1075 case T_ATM_E164_ADDR:
1076 c = UNI_IE_CGAD_PLAN_E164 +
1077 (UNI_IE_CGAD_TYPE_INTL
1078 << UNI_IE_CGAD_TYPE_SHIFT) +
1080 ie->ie_length = sizeof(Atm_addr_e164) + 1;
1082 case T_ATM_ENDSYS_ADDR:
1083 c = UNI_IE_CGAD_PLAN_NSAP +
1084 (UNI_IE_CGAD_TYPE_UNK
1085 << UNI_IE_CGAD_TYPE_SHIFT) +
1087 ie->ie_length = sizeof(Atm_addr_nsap) + 1;
1092 rc = usf_byte(usf, &c);
1097 * Encode the presentation and screening indicators
1100 c = ((ie->ie_cgad_pres_ind & UNI_IE_CGAD_PRES_MASK)
1101 << UNI_IE_CGAD_PRES_SHIFT) +
1102 (ie->ie_cgad_screen_ind &
1103 UNI_IE_CGAD_SCR_MASK) +
1105 rc = usf_byte(usf, &c);
1112 * Encode the ATM address
1114 rc = usf_enc_atm_addr(usf, &ie->ie_cgad_addr);
1121 * Encode a calling party subaddress information element
1124 * usf pointer to a unisig formatting structure
1125 * ie pointer to a cell rate IE structure
1129 * errno error encountered
1133 usf_enc_ie_cgsa(usf, ie)
1135 struct ie_generic *ie;
1141 * Encode the subaddress type
1143 switch(ie->ie_cgsa_addr.address_format) {
1144 case T_ATM_ENDSYS_ADDR:
1145 c = UNI_IE_CGSA_TYPE_AESA << UNI_IE_CGSA_TYPE_SHIFT;
1146 ie->ie_length = sizeof(Atm_addr_nsap) + 1;
1151 c |= UNI_IE_EXT_BIT;
1152 rc = usf_byte(usf, &c);
1157 * Encode the ATM address
1159 rc = usf_enc_atm_addr(usf, &ie->ie_cgsa_addr);
1166 * Encode a cause information element
1169 * usf pointer to a unisig formatting structure
1170 * ie pointer to a cell rate IE structure
1174 * errno error encountered
1178 usf_enc_ie_caus(usf, ie)
1180 struct ie_generic *ie;
1185 ATM_DEBUG2("usf_enc_ie_caus: usf=%p, ie=%p\n",
1191 * Encode the cause location
1193 c = (ie->ie_caus_loc & UNI_IE_CAUS_LOC_MASK) | UNI_IE_EXT_BIT;
1194 rc = usf_byte(usf, &c);
1200 * Encode the cause value
1202 c = ie->ie_caus_cause | UNI_IE_EXT_BIT;
1203 rc = usf_byte(usf, &c);
1209 * Encode any included diagnostics
1211 for (i = 0; i < ie->ie_caus_diag_len &&
1212 i < sizeof(ie->ie_caus_diagnostic);
1214 rc = usf_byte(usf, &ie->ie_caus_diagnostic[i]);
1225 * Encode a conection identifier information element
1228 * usf pointer to a unisig formatting structure
1229 * ie pointer to a cell rate IE structure
1233 * errno error encountered
1237 usf_enc_ie_cnid(usf, ie)
1239 struct ie_generic *ie;
1244 ATM_DEBUG2("usf_enc_ie_cnid: usf=%p, ie=%p\n",
1247 c = ((ie->ie_cnid_vp_sig & UNI_IE_CNID_VPSIG_MASK)
1248 << UNI_IE_CNID_VPSIG_SHIFT) +
1249 (ie->ie_cnid_pref_excl & UNI_IE_CNID_PREX_MASK) +
1251 rc = usf_byte(usf, &c);
1255 rc = usf_short(usf, &ie->ie_cnid_vpci);
1258 rc = usf_short(usf, &ie->ie_cnid_vci);
1268 * Encode a quality of service parameters information element
1271 * usf pointer to a unisig formatting structure
1272 * ie pointer to a cell rate IE structure
1276 * errno error encountered
1280 usf_enc_ie_qosp(usf, ie)
1282 struct ie_generic *ie;
1286 ATM_DEBUG2("usf_enc_ie_qosp: usf=%p, ie=%p\n",
1290 * Encode forward QoS class
1292 if (ie->ie_qosp_fwd_class == T_ATM_ABSENT ||
1293 ie->ie_qosp_bkwd_class == T_ATM_ABSENT)
1295 rc = usf_byte(usf, &ie->ie_qosp_fwd_class);
1300 * Encode backward QoS class
1302 rc = usf_byte(usf, &ie->ie_qosp_bkwd_class);
1310 * Encode a broadband repeat indicator information element
1313 * usf pointer to a unisig formatting structure
1314 * ie pointer to a cell rate IE structure
1318 * errno error encountered
1322 usf_enc_ie_brpi(usf, ie)
1324 struct ie_generic *ie;
1329 ATM_DEBUG2("usf_enc_ie_brpi: usf=%p, ie=%p\n",
1333 * Encode the repeat indicator
1335 c = ie->ie_brpi_ind + UNI_IE_EXT_BIT;
1336 rc = usf_byte(usf, &c);
1343 * Encode a restart indicator information element
1346 * usf pointer to a unisig formatting structure
1347 * ie pointer to a cell rate IE structure
1351 * errno error encountered
1355 usf_enc_ie_rsti(usf, ie)
1357 struct ie_generic *ie;
1362 ATM_DEBUG2("usf_enc_ie_rsti: usf=%p, ie=%p\n",
1366 * Encode the restart class
1368 c = (ie->ie_rsti_class & UNI_IE_RSTI_CLASS_MASK) |
1370 rc = usf_byte(usf, &c);
1378 * Encode a broadband sending complete information element
1381 * usf pointer to a unisig formatting structure
1382 * ie pointer to a broadband sending complete IE structure
1386 * errno error encountered
1390 usf_enc_ie_bsdc(usf, ie)
1392 struct ie_generic *ie;
1397 ATM_DEBUG2("usf_enc_ie_bsdc: usf=%p, ie=%p\n",
1401 * Encode the sending complete indicator
1403 c = UNI_IE_BSDC_IND | UNI_IE_EXT_BIT;
1404 rc = usf_byte(usf, &c);
1412 * Encode a transit network selection information element
1415 * usf pointer to a unisig formatting structure
1416 * ie pointer to a transit network selection rate IE structure
1420 * errno error encountered
1424 usf_enc_ie_trnt(usf, ie)
1426 struct ie_generic *ie;
1431 ATM_DEBUG2("usf_enc_ie_trnt: usf=%p, ie=%p\n",
1435 * Encode the sending complete indicator
1437 c = ((ie->ie_trnt_id_type & UNI_IE_TRNT_IDT_MASK) <<
1438 UNI_IE_TRNT_IDT_SHIFT) +
1439 (ie->ie_trnt_id_plan & UNI_IE_TRNT_IDP_MASK) +
1441 rc = usf_byte(usf, &c);
1447 * Encode the network identification
1449 for (i=0; i<ie->ie_trnt_id_len; i++) {
1450 rc = usf_byte(usf, &ie->ie_trnt_id[i]);
1461 * Encode an unsupported IE type
1464 * usf pointer to a unisig formatting structure
1465 * ie pointer to an IE structure
1472 usf_enc_ie_uimp(usf, ie)
1474 struct ie_generic *ie;
1481 * Encode an information element using field identifiers
1483 * The AAL parameters and ATM user cell rate IEs are formatted
1484 * with a one-byte identifier preceeding each field. The routine
1485 * encodes these IEs by using a table which relates the field
1486 * identifiers with the fields in the appropriate IE structure.
1489 * usf pointer to a unisig formatting structure
1490 * ie pointer to a cell rate IE structure
1491 * tbl pointer to an IE decoding table
1495 * errno error encountered
1499 usf_enc_ie_ident(usf, ie, tbl)
1501 struct ie_generic *ie;
1502 struct ie_decode_tbl *tbl;
1510 ATM_DEBUG3("usf_enc_ie_ident: usf=%p, ie=%p, tbl=%p\n",
1514 * Scan through the IE table
1517 for (i=0; tbl[i].ident; i++) {
1519 * Check whether to send the field
1521 cp = (char *) ((int)ie + tbl[i].f_offs);
1522 if (tbl[i].len == 0) {
1523 if ((*cp == T_NO || *cp == T_ATM_ABSENT))
1526 switch (tbl[i].f_size) {
1528 if (*(int8_t *)cp == T_ATM_ABSENT)
1532 if (*(int16_t *)cp == T_ATM_ABSENT)
1536 if (*(int32_t *)cp == T_ATM_ABSENT)
1542 "uni encode: id=%d,len=%d,off=%d,size=%d\n",
1543 tbl[i].ident, tbl[i].len,
1544 tbl[i].f_offs, tbl[i].f_size);
1550 * Encode the field identifier
1552 rc = usf_byte(usf, &tbl[i].ident);
1558 * Encode the field value
1560 switch (tbl[i].len) {
1564 switch (tbl[i].f_size) {
1566 cv = *(u_int8_t *)cp;
1569 cv = *(u_int16_t *)cp;
1572 cv = *(u_int32_t *)cp;
1577 rc = usf_byte(usf, &cv);
1581 switch (tbl[i].f_size) {
1583 sv = *(u_int16_t *)cp;
1586 sv = *(u_int32_t *)cp;
1591 rc = usf_short(usf, &sv);
1595 switch (tbl[i].f_size) {
1597 iv = *(u_int32_t *)cp;
1602 rc = usf_int3(usf, &iv);
1606 switch (tbl[i].f_size) {
1608 iv = *(u_int32_t *)cp;
1613 rc = usf_int(usf, &iv);
1626 ie->ie_length = len;
1632 * Encode an ATM address
1635 * usf pointer to a unisig formatting structure
1636 * addr pointer to an ATM address structure. The address
1637 * type must already be set correctly.
1641 * errno error encountered
1645 usf_enc_atm_addr(usf, addr)
1653 * Check the address type
1655 switch (addr->address_format) {
1656 case T_ATM_E164_ADDR:
1657 cp = (u_char *) addr->address;
1658 len = sizeof(Atm_addr_e164);
1660 case T_ATM_ENDSYS_ADDR:
1661 cp = (u_char *) addr->address;
1662 len = sizeof(Atm_addr_nsap);
1669 * Get the address bytes
1672 rc = usf_byte(usf, cp);