📄 tpam_nco.c
字号:
/* $Id: tpam_nco.c,v 1.1.2.1 2001/11/20 14:19:37 kai Exp $ * * Turbo PAM ISDN driver for Linux. * (Kernel Driver - Low Level NCO Manipulation) * * Copyright 2001 Stelian Pop <stelian.pop@fr.alcove.com>, Alc魐e * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * * For all support questions please contact: <support@auvertech.fr> * */#include <linux/pci.h>#include <linux/sched.h>#include <linux/tqueue.h>#include <linux/interrupt.h>#include <asm/io.h>#include "tpam.h"/* Local function prototypes */static struct sk_buff *build_NCOpacket(u16, u16, u16, u16, u16);static int extract_NCOParameter(struct sk_buff *, u8, void *, u16);/* * Build a NCO packet (PCI message). * * messageID: the message type (ID_*) * size: size of the TLV block * data_size: size of the data block * ack: packet needs to send ack upon send * ack_size: size of data to be acknowledged upon send * * Return: the sk_buff filled with the NCO packet, or NULL if error. */static struct sk_buff *build_NCOpacket(u16 messageID, u16 size, u16 data_size, u16 ack, u16 ack_size) { struct sk_buff *skb; skb_header *h; pci_mpb *p; u16 finalsize; /* reserve enough space for the sk_buff header, the pci * header, * size bytes for the TLV block, size bytes for the data and 4 more * bytes in order to make sure we can write dwords to the board. */ finalsize = sizeof(skb_header) + sizeof(pci_mpb) + size + data_size + 4; /* allocate the sk_buff */ if (!(skb = alloc_skb(finalsize, GFP_ATOMIC))) { printk(KERN_ERR "TurboPAM(make_NCOpacket): alloc_skb failed\n"); return NULL; } /* construct the skb_header */ h = (skb_header *)skb_put(skb, sizeof(skb_header)); h->size = sizeof(pci_mpb) + size; h->data_size = data_size; h->ack = ack; h->ack_size = ack_size; /* construct the pci_mpb */ p = (pci_mpb *)skb_put(skb, sizeof(pci_mpb)); p->exID = 0; p->flags = 0; p->errorCode = 0; p->messageID = messageID; p->maximumBlockTLVSize = MPB_MAXIMUMBLOCKTLVSIZE; p->actualBlockTLVSize = size; p->maximumDataSize = MPB_MAXIMUMDATASIZE; p->actualDataSize = data_size; return skb;}/* * Build a ACreateNCOReq message. * * phone: the local phone number. * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_ACreateNCOReq(const u8 *phone) { struct sk_buff *skb; u8 *tlv; dprintk("TurboPAM(build_ACreateNCOReq): phone=%s\n", phone); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_ACreateNCOReq, 23 + strlen(phone), 0, 0, 0))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 3); *tlv = PAR_NCOType; *(tlv+1) = 1; *(tlv+2) = 5; /* mistery value... */ tlv = (u8 *)skb_put(skb, 4); *tlv = PAR_U3Protocol; *(tlv+1) = 2; *(tlv+2) = 4; /* no level 3 protocol */ *(tlv+3) = 1; /* HDLC in level 2 */ tlv = (u8 *)skb_put(skb, 3); *tlv = PAR_Cdirection; *(tlv+1) = 1; *(tlv+2) = 3; /* PCI_DIRECTION_BOTH */ tlv = (u8 *)skb_put(skb, 3); *tlv = PAR_Udirection; *(tlv+1) = 1; *(tlv+2) = 3; /* PCI_DIRECTION_BOTH */ tlv = (u8 *)skb_put(skb, 4); *tlv = PAR_BearerCap; *(tlv+1) = 2; *(tlv+2) = 0x88; *(tlv+3) = 0x90; tlv = (u8 *)skb_put(skb, 6 + strlen(phone)); *tlv = PAR_CallingNumber; *(tlv+1) = strlen(phone) + 4; *(tlv+2) = 0x01; /* international */ *(tlv+3) = 0x01; /* isdn */ *(tlv+4) = 0x00; *(tlv+5) = 0x00; memcpy(tlv + 6, phone, strlen(phone)); return skb;}/* * Build a ADestroyNCOReq message. * * ncoid: the NCO id. * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_ADestroyNCOReq(u32 ncoid) { struct sk_buff *skb; u8 *tlv; dprintk("TurboPAM(build_ADestroyNCOReq): ncoid=%lu\n", (unsigned long)ncoid); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_ADestroyNCOReq, 6, 0, 0, 0))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 6); *tlv = PAR_NCOID; *(tlv+1) = 4; *((u32 *)(tlv+2)) = ncoid; return skb;}/* * Build a CConnectReq message. * * ncoid: the NCO id. * called: the destination phone number * hdlc: type of connection: 1 (HDLC) or 0(modem) * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_CConnectReq(u32 ncoid, const u8 *called, u8 hdlc) { struct sk_buff *skb; u8 *tlv; dprintk("TurboPAM(build_CConnectReq): ncoid=%lu, called=%s, hdlc=%d\n", (unsigned long)ncoid, called, hdlc); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_CConnectReq, 20 + strlen(called), 0, 0, 0))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 6); *tlv = PAR_NCOID; *(tlv+1) = 4; *((u32 *)(tlv+2)) = ncoid; tlv = (u8 *)skb_put(skb, 4 + strlen(called)); *tlv = PAR_CalledNumber; *(tlv+1) = strlen(called) + 2; *(tlv+2) = 0x01; /* international */ *(tlv+3) = 0x01; /* isdn */ memcpy(tlv + 4, called, strlen(called)); tlv = (u8 *)skb_put(skb, 3); *tlv = PAR_BearerCap; *(tlv+1) = 1; *(tlv+2) = hdlc ? 0x88 /* HDLC */ : 0x80 /* MODEM */; tlv = (u8 *)skb_put(skb, 4); *tlv = PAR_HLC; *(tlv+1) = 2; *(tlv+2) = 0x2; *(tlv+3) = 0x7f; tlv = (u8 *)skb_put(skb, 3); *tlv = PAR_Facility; *(tlv+1) = 1; *(tlv+2) = 2; return skb;}/* * Build a CConnectRsp message. * * ncoid: the NCO id. * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_CConnectRsp(u32 ncoid) { struct sk_buff *skb; u8 *tlv; dprintk("TurboPAM(build_CConnectRsp): ncoid=%lu\n", (unsigned long)ncoid); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_CConnectRsp, 6, 0, 0, 0))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 6); *tlv = PAR_NCOID; *(tlv+1) = 4; *((u32 *)(tlv+2)) = ncoid; return skb;}/* * Build a CDisconnectReq message. * * ncoid: the NCO id. * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_CDisconnectReq(u32 ncoid) { struct sk_buff *skb; u8 *tlv; dprintk("TurboPAM(build_CDisconnectReq): ncoid=%lu\n", (unsigned long)ncoid); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_CDisconnectReq, 6, 0, 0, 0))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 6); *tlv = PAR_NCOID; *(tlv+1) = 4; *((u32 *)(tlv+2)) = ncoid; return skb;}/* * Build a CDisconnectRsp message. * * ncoid: the NCO id. * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_CDisconnectRsp(u32 ncoid) { struct sk_buff *skb; u8 *tlv; dprintk("TurboPAM(build_CDisconnectRsp): ncoid=%lu\n", (unsigned long)ncoid); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_CDisconnectRsp, 6, 0, 0, 0))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 6); *tlv = PAR_NCOID; *(tlv+1) = 4; *((u32 *)(tlv+2)) = ncoid; return skb;}/* * Build a U3DataReq message. * * ncoid: the NCO id. * data: the data to be send * len: length of the data * ack: send ack upon send * ack_size: size of data to be acknowledged upon send * * Return: the sk_buff filled with the NCO packet, or NULL if error. */struct sk_buff *build_U3DataReq(u32 ncoid, void *data, u16 len, u16 ack, u16 ack_size) { struct sk_buff *skb; u8 *tlv; void *p; dprintk("TurboPAM(build_U3DataReq): " "ncoid=%lu, len=%d, ack=%d, ack_size=%d\n", (unsigned long)ncoid, len, ack, ack_size); /* build the NCO packet */ if (!(skb = build_NCOpacket(ID_U3DataReq, 6, len, ack, ack_size))) return NULL; /* add the parameters */ tlv = (u8 *)skb_put(skb, 6); *tlv = PAR_NCOID; *(tlv+1) = 4; *((u32 *)(tlv+2)) = ncoid; p = skb_put(skb, len); memcpy(p, data, len);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -