📄 capi.c
字号:
/* * Copyright (C) 1996 Universidade de Lisboa * * Written by Pedro Roque Marques (roque@di.fc.ul.pt) * * This software may be used and distributed according to the terms of * the GNU Public License, incorporated herein by reference. *//* * CAPI encoder/decoder for * Portugal Telecom CAPI 2.0 * * Not compatible with the AVM Gmbh. CAPI 2.0 *//* * Documentation: * - "Common ISDN API - Perfil Portugu阺 - Vers鉶 2.1", * Telecom Portugal, Fev 1992. * - "Common ISDN API - Especifica玢o de protocolos para * acesso aos canais B", Inesc, Jan 1994. *//* * TODO: better decoding of Information Elements * for debug purposes mainly * encode our number in CallerPN and ConnectedPN */#define __NO_VERSION__#include <linux/module.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/malloc.h>#include <linux/mm.h>#include <linux/tqueue.h>#include <linux/skbuff.h>#include <asm/io.h>#include <asm/string.h>#include <linux/isdnif.h>#include "pcbit.h"#include "edss1.h"#include "capi.h"/* * Encoding of CAPI messages * */int capi_conn_req(const char * calledPN, struct sk_buff **skb, int proto){ ushort len; /* * length * AppInfoMask - 2 * BC0 - 3 * BC1 - 1 * Chan - 2 * Keypad - 1 * CPN - 1 * CPSA - 1 * CalledPN - 2 + strlen * CalledPSA - 1 * rest... - 4 * ---------------- * Total 18 + strlen */ len = 18 + strlen(calledPN); if (proto == ISDN_PROTO_L2_TRANS) len++; if ((*skb = dev_alloc_skb(len)) == NULL) { printk(KERN_WARNING "capi_conn_req: alloc_skb failed\n"); return -1; } /* InfoElmMask */ *((ushort*) skb_put(*skb, 2)) = AppInfoMask; if (proto == ISDN_PROTO_L2_TRANS) { /* Bearer Capability - Mandatory*/ *(skb_put(*skb, 1)) = 3; /* BC0.Length */ *(skb_put(*skb, 1)) = 0x80; /* Speech */ *(skb_put(*skb, 1)) = 0x10; /* Circuit Mode */ *(skb_put(*skb, 1)) = 0x23; /* A-law */ } else { /* Bearer Capability - Mandatory*/ *(skb_put(*skb, 1)) = 2; /* BC0.Length */ *(skb_put(*skb, 1)) = 0x88; /* Digital Information */ *(skb_put(*skb, 1)) = 0x90; /* BC0.Octect4 */ } /* Bearer Capability - Optional*/ *(skb_put(*skb, 1)) = 0; /* BC1.Length = 0 */ *(skb_put(*skb, 1)) = 1; /* ChannelID.Length = 1 */ *(skb_put(*skb, 1)) = 0x83; /* Basic Interface - Any Channel */ *(skb_put(*skb, 1)) = 0; /* Keypad.Length = 0 */ *(skb_put(*skb, 1)) = 0; /* CallingPN.Length = 0 */ *(skb_put(*skb, 1)) = 0; /* CallingPSA.Length = 0 */ /* Called Party Number */ *(skb_put(*skb, 1)) = strlen(calledPN) + 1; *(skb_put(*skb, 1)) = 0x81; memcpy(skb_put(*skb, strlen(calledPN)), calledPN, strlen(calledPN)); /* '#' */ *(skb_put(*skb, 1)) = 0; /* CalledPSA.Length = 0 */ /* LLC.Length = 0; */ /* HLC0.Length = 0; */ /* HLC1.Length = 0; */ /* UTUS.Length = 0; */ memset(skb_put(*skb, 4), 0, 4); return len;}int capi_conn_resp(struct pcbit_chan* chan, struct sk_buff **skb){ if ((*skb = dev_alloc_skb(5)) == NULL) { printk(KERN_WARNING "capi_conn_resp: alloc_skb failed\n"); return -1; } *((ushort*) skb_put(*skb, 2) ) = chan->callref; *(skb_put(*skb, 1)) = 0x01; /* ACCEPT_CALL */ *(skb_put(*skb, 1)) = 0; *(skb_put(*skb, 1)) = 0; return 5;}int capi_conn_active_req(struct pcbit_chan* chan, struct sk_buff **skb){ /* * 8 bytes */ if ((*skb = dev_alloc_skb(8)) == NULL) { printk(KERN_WARNING "capi_conn_active_req: alloc_skb failed\n"); return -1; } *((ushort*) skb_put(*skb, 2) ) = chan->callref; #ifdef DEBUG printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref); #endif *(skb_put(*skb, 1)) = 0; /* BC.Length = 0; */ *(skb_put(*skb, 1)) = 0; /* ConnectedPN.Length = 0 */ *(skb_put(*skb, 1)) = 0; /* PSA.Length */ *(skb_put(*skb, 1)) = 0; /* LLC.Length = 0; */ *(skb_put(*skb, 1)) = 0; /* HLC.Length = 0; */ *(skb_put(*skb, 1)) = 0; /* UTUS.Length = 0; */ return 8;}int capi_conn_active_resp(struct pcbit_chan* chan, struct sk_buff **skb){ /* * 2 bytes */ if ((*skb = dev_alloc_skb(2)) == NULL) { printk(KERN_WARNING "capi_conn_active_resp: alloc_skb failed\n"); return -1; } *((ushort*) skb_put(*skb, 2) ) = chan->callref; return 2;}int capi_select_proto_req(struct pcbit_chan *chan, struct sk_buff **skb, int outgoing){ /* * 18 bytes */ if ((*skb = dev_alloc_skb(18)) == NULL) { printk(KERN_WARNING "capi_select_proto_req: alloc_skb failed\n"); return -1; } *((ushort*) skb_put(*skb, 2) ) = chan->callref; /* Layer2 protocol */ switch (chan->proto) { case ISDN_PROTO_L2_X75I: *(skb_put(*skb, 1)) = 0x05; /* LAPB */ break; case ISDN_PROTO_L2_HDLC: *(skb_put(*skb, 1)) = 0x02; break; case ISDN_PROTO_L2_TRANS: /* * Voice (a-law) */ *(skb_put(*skb, 1)) = 0x06; break; default:#ifdef DEBUG printk(KERN_DEBUG "Transparent\n");#endif *(skb_put(*skb, 1)) = 0x03; break; } *(skb_put(*skb, 1)) = (outgoing ? 0x02 : 0x42); /* Don't ask */ *(skb_put(*skb, 1)) = 0x00; *((ushort *) skb_put(*skb, 2)) = MRU; *(skb_put(*skb, 1)) = 0x08; /* Modulo */ *(skb_put(*skb, 1)) = 0x07; /* Max Window */ *(skb_put(*skb, 1)) = 0x01; /* No Layer3 Protocol */ /* * 2 - layer3 MTU [10] * - Modulo [12] * - Window * - layer1 proto [14] * - bitrate * - sub-channel [16] * - layer1dataformat [17] */ memset(skb_put(*skb, 8), 0, 8); return 18;}int capi_activate_transp_req(struct pcbit_chan *chan, struct sk_buff **skb){ if ((*skb = dev_alloc_skb(7)) == NULL) { printk(KERN_WARNING "capi_activate_transp_req: alloc_skb failed\n"); return -1; } *((ushort*) skb_put(*skb, 2) ) = chan->callref; *(skb_put(*skb, 1)) = chan->layer2link; /* Layer2 id */ *(skb_put(*skb, 1)) = 0x00; /* Transmit by default */ *((ushort *) skb_put(*skb, 2)) = MRU; *(skb_put(*skb, 1)) = 0x01; /* Enables reception*/ return 7;}int capi_tdata_req(struct pcbit_chan* chan, struct sk_buff *skb){ ushort data_len; /* * callref - 2 * layer2link - 1 * wBlockLength - 2 * data - 4 * sernum - 1 */ data_len = skb->len; if(skb_headroom(skb) < 10) { printk(KERN_CRIT "No headspace (%u) on headroom %p for capi header\n", skb_headroom(skb), skb); } else { skb_push(skb, 10); } *((u16 *) (skb->data)) = chan->callref; skb->data[2] = chan->layer2link; *((u16 *) (skb->data + 3)) = data_len; chan->s_refnum = (chan->s_refnum + 1) % 8; *((u32 *) (skb->data + 5)) = chan->s_refnum; skb->data[9] = 0; /* HDLC frame number */ return 10;}int capi_tdata_resp(struct pcbit_chan *chan, struct sk_buff ** skb) { if ((*skb = dev_alloc_skb(4)) == NULL) { printk(KERN_WARNING "capi_tdata_resp: alloc_skb failed\n"); return -1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -