at v2.6.21 522 lines 15 kB view raw
1/* $Id: capiutil.h,v 1.5.6.2 2001/09/23 22:24:33 kai Exp $ 2 * 3 * CAPI 2.0 defines & types 4 * 5 * From CAPI 2.0 Development Kit AVM 1995 (msg.c) 6 * Rewritten for Linux 1996 by Carsten Paeth <calle@calle.de> 7 * 8 * This software may be used and distributed according to the terms 9 * of the GNU General Public License, incorporated herein by reference. 10 * 11 */ 12 13#ifndef __CAPIUTIL_H__ 14#define __CAPIUTIL_H__ 15 16#include <asm/types.h> 17 18#define CAPIMSG_BASELEN 8 19#define CAPIMSG_U8(m, off) (m[off]) 20#define CAPIMSG_U16(m, off) (m[off]|(m[(off)+1]<<8)) 21#define CAPIMSG_U32(m, off) (m[off]|(m[(off)+1]<<8)|(m[(off)+2]<<16)|(m[(off)+3]<<24)) 22#define CAPIMSG_LEN(m) CAPIMSG_U16(m,0) 23#define CAPIMSG_APPID(m) CAPIMSG_U16(m,2) 24#define CAPIMSG_COMMAND(m) CAPIMSG_U8(m,4) 25#define CAPIMSG_SUBCOMMAND(m) CAPIMSG_U8(m,5) 26#define CAPIMSG_CMD(m) (((m[4])<<8)|(m[5])) 27#define CAPIMSG_MSGID(m) CAPIMSG_U16(m,6) 28#define CAPIMSG_CONTROLLER(m) (m[8] & 0x7f) 29#define CAPIMSG_CONTROL(m) CAPIMSG_U32(m, 8) 30#define CAPIMSG_NCCI(m) CAPIMSG_CONTROL(m) 31#define CAPIMSG_DATALEN(m) CAPIMSG_U16(m,16) /* DATA_B3_REQ */ 32 33static inline void capimsg_setu8(void *m, int off, __u8 val) 34{ 35 ((__u8 *)m)[off] = val; 36} 37 38static inline void capimsg_setu16(void *m, int off, __u16 val) 39{ 40 ((__u8 *)m)[off] = val & 0xff; 41 ((__u8 *)m)[off+1] = (val >> 8) & 0xff; 42} 43 44static inline void capimsg_setu32(void *m, int off, __u32 val) 45{ 46 ((__u8 *)m)[off] = val & 0xff; 47 ((__u8 *)m)[off+1] = (val >> 8) & 0xff; 48 ((__u8 *)m)[off+2] = (val >> 16) & 0xff; 49 ((__u8 *)m)[off+3] = (val >> 24) & 0xff; 50} 51 52#define CAPIMSG_SETLEN(m, len) capimsg_setu16(m, 0, len) 53#define CAPIMSG_SETAPPID(m, applid) capimsg_setu16(m, 2, applid) 54#define CAPIMSG_SETCOMMAND(m,cmd) capimsg_setu8(m, 4, cmd) 55#define CAPIMSG_SETSUBCOMMAND(m, cmd) capimsg_setu8(m, 5, cmd) 56#define CAPIMSG_SETMSGID(m, msgid) capimsg_setu16(m, 6, msgid) 57#define CAPIMSG_SETCONTROL(m, contr) capimsg_setu32(m, 8, contr) 58#define CAPIMSG_SETDATALEN(m, len) capimsg_setu16(m, 16, len) 59 60/*----- basic-type definitions -----*/ 61 62typedef __u8 *_cstruct; 63 64typedef enum { 65 CAPI_COMPOSE, 66 CAPI_DEFAULT 67} _cmstruct; 68 69/* 70 The _cmsg structure contains all possible CAPI 2.0 parameter. 71 All parameters are stored here first. The function CAPI_CMSG_2_MESSAGE 72 assembles the parameter and builds CAPI2.0 conform messages. 73 CAPI_MESSAGE_2_CMSG disassembles CAPI 2.0 messages and stores the 74 parameter in the _cmsg structure 75 */ 76 77typedef struct { 78 /* Header */ 79 __u16 ApplId; 80 __u8 Command; 81 __u8 Subcommand; 82 __u16 Messagenumber; 83 84 /* Parameter */ 85 union { 86 __u32 adrController; 87 __u32 adrPLCI; 88 __u32 adrNCCI; 89 } adr; 90 91 _cmstruct AdditionalInfo; 92 _cstruct B1configuration; 93 __u16 B1protocol; 94 _cstruct B2configuration; 95 __u16 B2protocol; 96 _cstruct B3configuration; 97 __u16 B3protocol; 98 _cstruct BC; 99 _cstruct BChannelinformation; 100 _cmstruct BProtocol; 101 _cstruct CalledPartyNumber; 102 _cstruct CalledPartySubaddress; 103 _cstruct CallingPartyNumber; 104 _cstruct CallingPartySubaddress; 105 __u32 CIPmask; 106 __u32 CIPmask2; 107 __u16 CIPValue; 108 __u32 Class; 109 _cstruct ConnectedNumber; 110 _cstruct ConnectedSubaddress; 111 __u32 Data; 112 __u16 DataHandle; 113 __u16 DataLength; 114 _cstruct FacilityConfirmationParameter; 115 _cstruct Facilitydataarray; 116 _cstruct FacilityIndicationParameter; 117 _cstruct FacilityRequestParameter; 118 __u16 FacilitySelector; 119 __u16 Flags; 120 __u32 Function; 121 _cstruct HLC; 122 __u16 Info; 123 _cstruct InfoElement; 124 __u32 InfoMask; 125 __u16 InfoNumber; 126 _cstruct Keypadfacility; 127 _cstruct LLC; 128 _cstruct ManuData; 129 __u32 ManuID; 130 _cstruct NCPI; 131 __u16 Reason; 132 __u16 Reason_B3; 133 __u16 Reject; 134 _cstruct Useruserdata; 135 136 /* intern */ 137 unsigned l, p; 138 unsigned char *par; 139 __u8 *m; 140 141 /* buffer to construct message */ 142 __u8 buf[180]; 143 144} _cmsg; 145 146/* 147 * capi_cmsg2message() assembles the parameter from _cmsg to a CAPI 2.0 148 * conform message 149 */ 150unsigned capi_cmsg2message(_cmsg * cmsg, __u8 * msg); 151 152/* 153 * capi_message2cmsg disassembles a CAPI message an writes the parameter 154 * into _cmsg for easy access 155 */ 156unsigned capi_message2cmsg(_cmsg * cmsg, __u8 * msg); 157 158/* 159 * capi_cmsg_header() fills the _cmsg structure with default values, so only 160 * parameter with non default values must be changed before sending the 161 * message. 162 */ 163unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId, 164 __u8 _Command, __u8 _Subcommand, 165 __u16 _Messagenumber, __u32 _Controller); 166 167/* 168 * capi_info2str generated a readable string for Capi2.0 reasons. 169 */ 170char *capi_info2str(__u16 reason); 171 172/*-----------------------------------------------------------------------*/ 173 174/* 175 * Debugging / Tracing functions 176 */ 177 178char *capi_cmd2str(__u8 cmd, __u8 subcmd); 179 180typedef struct { 181 u_char *buf; 182 u_char *p; 183 size_t size; 184 size_t pos; 185} _cdebbuf; 186 187#define CDEBUG_SIZE 1024 188#define CDEBUG_GSIZE 4096 189 190_cdebbuf *cdebbuf_alloc(void); 191void cdebbuf_free(_cdebbuf *cdb); 192int cdebug_init(void); 193void cdebug_exit(void); 194 195_cdebbuf *capi_cmsg2str(_cmsg *cmsg); 196_cdebbuf *capi_message2str(__u8 *msg); 197 198/*-----------------------------------------------------------------------*/ 199 200static inline void capi_cmsg_answer(_cmsg * cmsg) 201{ 202 cmsg->Subcommand |= 0x01; 203} 204 205/*-----------------------------------------------------------------------*/ 206 207static inline void capi_fill_CONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 208 __u32 adr, 209 _cstruct NCPI) 210{ 211 capi_cmsg_header(cmsg, ApplId, 0x82, 0x80, Messagenumber, adr); 212 cmsg->NCPI = NCPI; 213} 214 215static inline void capi_fill_FACILITY_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 216 __u32 adr, 217 __u16 FacilitySelector, 218 _cstruct FacilityRequestParameter) 219{ 220 capi_cmsg_header(cmsg, ApplId, 0x80, 0x80, Messagenumber, adr); 221 cmsg->FacilitySelector = FacilitySelector; 222 cmsg->FacilityRequestParameter = FacilityRequestParameter; 223} 224 225static inline void capi_fill_INFO_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 226 __u32 adr, 227 _cstruct CalledPartyNumber, 228 _cstruct BChannelinformation, 229 _cstruct Keypadfacility, 230 _cstruct Useruserdata, 231 _cstruct Facilitydataarray) 232{ 233 capi_cmsg_header(cmsg, ApplId, 0x08, 0x80, Messagenumber, adr); 234 cmsg->CalledPartyNumber = CalledPartyNumber; 235 cmsg->BChannelinformation = BChannelinformation; 236 cmsg->Keypadfacility = Keypadfacility; 237 cmsg->Useruserdata = Useruserdata; 238 cmsg->Facilitydataarray = Facilitydataarray; 239} 240 241static inline void capi_fill_LISTEN_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 242 __u32 adr, 243 __u32 InfoMask, 244 __u32 CIPmask, 245 __u32 CIPmask2, 246 _cstruct CallingPartyNumber, 247 _cstruct CallingPartySubaddress) 248{ 249 capi_cmsg_header(cmsg, ApplId, 0x05, 0x80, Messagenumber, adr); 250 cmsg->InfoMask = InfoMask; 251 cmsg->CIPmask = CIPmask; 252 cmsg->CIPmask2 = CIPmask2; 253 cmsg->CallingPartyNumber = CallingPartyNumber; 254 cmsg->CallingPartySubaddress = CallingPartySubaddress; 255} 256 257static inline void capi_fill_ALERT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 258 __u32 adr, 259 _cstruct BChannelinformation, 260 _cstruct Keypadfacility, 261 _cstruct Useruserdata, 262 _cstruct Facilitydataarray) 263{ 264 capi_cmsg_header(cmsg, ApplId, 0x01, 0x80, Messagenumber, adr); 265 cmsg->BChannelinformation = BChannelinformation; 266 cmsg->Keypadfacility = Keypadfacility; 267 cmsg->Useruserdata = Useruserdata; 268 cmsg->Facilitydataarray = Facilitydataarray; 269} 270 271static inline void capi_fill_CONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 272 __u32 adr, 273 __u16 CIPValue, 274 _cstruct CalledPartyNumber, 275 _cstruct CallingPartyNumber, 276 _cstruct CalledPartySubaddress, 277 _cstruct CallingPartySubaddress, 278 __u16 B1protocol, 279 __u16 B2protocol, 280 __u16 B3protocol, 281 _cstruct B1configuration, 282 _cstruct B2configuration, 283 _cstruct B3configuration, 284 _cstruct BC, 285 _cstruct LLC, 286 _cstruct HLC, 287 _cstruct BChannelinformation, 288 _cstruct Keypadfacility, 289 _cstruct Useruserdata, 290 _cstruct Facilitydataarray) 291{ 292 293 capi_cmsg_header(cmsg, ApplId, 0x02, 0x80, Messagenumber, adr); 294 cmsg->CIPValue = CIPValue; 295 cmsg->CalledPartyNumber = CalledPartyNumber; 296 cmsg->CallingPartyNumber = CallingPartyNumber; 297 cmsg->CalledPartySubaddress = CalledPartySubaddress; 298 cmsg->CallingPartySubaddress = CallingPartySubaddress; 299 cmsg->B1protocol = B1protocol; 300 cmsg->B2protocol = B2protocol; 301 cmsg->B3protocol = B3protocol; 302 cmsg->B1configuration = B1configuration; 303 cmsg->B2configuration = B2configuration; 304 cmsg->B3configuration = B3configuration; 305 cmsg->BC = BC; 306 cmsg->LLC = LLC; 307 cmsg->HLC = HLC; 308 cmsg->BChannelinformation = BChannelinformation; 309 cmsg->Keypadfacility = Keypadfacility; 310 cmsg->Useruserdata = Useruserdata; 311 cmsg->Facilitydataarray = Facilitydataarray; 312} 313 314static inline void capi_fill_DATA_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 315 __u32 adr, 316 __u32 Data, 317 __u16 DataLength, 318 __u16 DataHandle, 319 __u16 Flags) 320{ 321 322 capi_cmsg_header(cmsg, ApplId, 0x86, 0x80, Messagenumber, adr); 323 cmsg->Data = Data; 324 cmsg->DataLength = DataLength; 325 cmsg->DataHandle = DataHandle; 326 cmsg->Flags = Flags; 327} 328 329static inline void capi_fill_DISCONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 330 __u32 adr, 331 _cstruct BChannelinformation, 332 _cstruct Keypadfacility, 333 _cstruct Useruserdata, 334 _cstruct Facilitydataarray) 335{ 336 337 capi_cmsg_header(cmsg, ApplId, 0x04, 0x80, Messagenumber, adr); 338 cmsg->BChannelinformation = BChannelinformation; 339 cmsg->Keypadfacility = Keypadfacility; 340 cmsg->Useruserdata = Useruserdata; 341 cmsg->Facilitydataarray = Facilitydataarray; 342} 343 344static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 345 __u32 adr, 346 _cstruct NCPI) 347{ 348 349 capi_cmsg_header(cmsg, ApplId, 0x84, 0x80, Messagenumber, adr); 350 cmsg->NCPI = NCPI; 351} 352 353static inline void capi_fill_MANUFACTURER_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 354 __u32 adr, 355 __u32 ManuID, 356 __u32 Class, 357 __u32 Function, 358 _cstruct ManuData) 359{ 360 361 capi_cmsg_header(cmsg, ApplId, 0xff, 0x80, Messagenumber, adr); 362 cmsg->ManuID = ManuID; 363 cmsg->Class = Class; 364 cmsg->Function = Function; 365 cmsg->ManuData = ManuData; 366} 367 368static inline void capi_fill_RESET_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 369 __u32 adr, 370 _cstruct NCPI) 371{ 372 373 capi_cmsg_header(cmsg, ApplId, 0x87, 0x80, Messagenumber, adr); 374 cmsg->NCPI = NCPI; 375} 376 377static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 378 __u32 adr, 379 __u16 B1protocol, 380 __u16 B2protocol, 381 __u16 B3protocol, 382 _cstruct B1configuration, 383 _cstruct B2configuration, 384 _cstruct B3configuration) 385{ 386 387 capi_cmsg_header(cmsg, ApplId, 0x41, 0x80, Messagenumber, adr); 388 cmsg->B1protocol = B1protocol; 389 cmsg->B2protocol = B2protocol; 390 cmsg->B3protocol = B3protocol; 391 cmsg->B1configuration = B1configuration; 392 cmsg->B2configuration = B2configuration; 393 cmsg->B3configuration = B3configuration; 394} 395 396static inline void capi_fill_CONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 397 __u32 adr, 398 __u16 Reject, 399 __u16 B1protocol, 400 __u16 B2protocol, 401 __u16 B3protocol, 402 _cstruct B1configuration, 403 _cstruct B2configuration, 404 _cstruct B3configuration, 405 _cstruct ConnectedNumber, 406 _cstruct ConnectedSubaddress, 407 _cstruct LLC, 408 _cstruct BChannelinformation, 409 _cstruct Keypadfacility, 410 _cstruct Useruserdata, 411 _cstruct Facilitydataarray) 412{ 413 capi_cmsg_header(cmsg, ApplId, 0x02, 0x83, Messagenumber, adr); 414 cmsg->Reject = Reject; 415 cmsg->B1protocol = B1protocol; 416 cmsg->B2protocol = B2protocol; 417 cmsg->B3protocol = B3protocol; 418 cmsg->B1configuration = B1configuration; 419 cmsg->B2configuration = B2configuration; 420 cmsg->B3configuration = B3configuration; 421 cmsg->ConnectedNumber = ConnectedNumber; 422 cmsg->ConnectedSubaddress = ConnectedSubaddress; 423 cmsg->LLC = LLC; 424 cmsg->BChannelinformation = BChannelinformation; 425 cmsg->Keypadfacility = Keypadfacility; 426 cmsg->Useruserdata = Useruserdata; 427 cmsg->Facilitydataarray = Facilitydataarray; 428} 429 430static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 431 __u32 adr) 432{ 433 434 capi_cmsg_header(cmsg, ApplId, 0x03, 0x83, Messagenumber, adr); 435} 436 437static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 438 __u32 adr) 439{ 440 441 capi_cmsg_header(cmsg, ApplId, 0x83, 0x83, Messagenumber, adr); 442} 443 444static inline void capi_fill_CONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 445 __u32 adr, 446 __u16 Reject, 447 _cstruct NCPI) 448{ 449 capi_cmsg_header(cmsg, ApplId, 0x82, 0x83, Messagenumber, adr); 450 cmsg->Reject = Reject; 451 cmsg->NCPI = NCPI; 452} 453 454static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 455 __u32 adr) 456{ 457 458 capi_cmsg_header(cmsg, ApplId, 0x88, 0x83, Messagenumber, adr); 459} 460 461static inline void capi_fill_DATA_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 462 __u32 adr, 463 __u16 DataHandle) 464{ 465 466 capi_cmsg_header(cmsg, ApplId, 0x86, 0x83, Messagenumber, adr); 467 cmsg->DataHandle = DataHandle; 468} 469 470static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 471 __u32 adr) 472{ 473 474 capi_cmsg_header(cmsg, ApplId, 0x84, 0x83, Messagenumber, adr); 475} 476 477static inline void capi_fill_DISCONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 478 __u32 adr) 479{ 480 481 capi_cmsg_header(cmsg, ApplId, 0x04, 0x83, Messagenumber, adr); 482} 483 484static inline void capi_fill_FACILITY_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 485 __u32 adr, 486 __u16 FacilitySelector) 487{ 488 489 capi_cmsg_header(cmsg, ApplId, 0x80, 0x83, Messagenumber, adr); 490 cmsg->FacilitySelector = FacilitySelector; 491} 492 493static inline void capi_fill_INFO_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 494 __u32 adr) 495{ 496 497 capi_cmsg_header(cmsg, ApplId, 0x08, 0x83, Messagenumber, adr); 498} 499 500static inline void capi_fill_MANUFACTURER_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 501 __u32 adr, 502 __u32 ManuID, 503 __u32 Class, 504 __u32 Function, 505 _cstruct ManuData) 506{ 507 508 capi_cmsg_header(cmsg, ApplId, 0xff, 0x83, Messagenumber, adr); 509 cmsg->ManuID = ManuID; 510 cmsg->Class = Class; 511 cmsg->Function = Function; 512 cmsg->ManuData = ManuData; 513} 514 515static inline void capi_fill_RESET_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber, 516 __u32 adr) 517{ 518 519 capi_cmsg_header(cmsg, ApplId, 0x87, 0x83, Messagenumber, adr); 520} 521 522#endif /* __CAPIUTIL_H__ */