⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hycapi.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: hycapi.c,v 1.8 2000/11/22 17:13:13 kai Exp $ * * Linux driver for HYSDN cards, CAPI2.0-Interface. * written by Ulrich Albrecht (u.albrecht@hypercope.de) for Hypercope GmbH * * Copyright 2000 by Hypercope GmbH * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */#define __NO_VERSION__#include <linux/module.h>#include <linux/version.h>#include <linux/signal.h>#include <linux/kernel.h>#include <linux/skbuff.h>#define	VER_DRIVER	0#define	VER_CARDTYPE	1#define	VER_HWID	2#define	VER_SERIAL	3#define	VER_OPTION	4#define	VER_PROTO	5#define	VER_PROFILE	6#define	VER_CAPI	7#include "hysdn_defs.h"#include <linux/kernelcapi.h>static char hycapi_revision[]="$Revision: 1.8 $";typedef struct _hycapi_appl {	unsigned int ctrl_mask;	capi_register_params rp;	struct sk_buff *listen_req[CAPI_MAXCONTR];} hycapi_appl;static hycapi_appl hycapi_applications[CAPI_MAXAPPL];static inline int _hycapi_appCheck(int app_id, int ctrl_no){	if((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) ||	   (app_id > CAPI_MAXAPPL))	{		printk(KERN_ERR "HYCAPI: Invalid request app_id %d for controller %d", app_id, ctrl_no);		return -1;	}	return ((hycapi_applications[app_id-1].ctrl_mask & (1 << (ctrl_no-1))) != 0);}struct capi_driver_interface *hy_di = NULL;/******************************Kernel-Capi callback reset_ctr******************************/     void hycapi_reset_ctr(struct capi_ctr *ctrl){#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "HYCAPI hycapi_reset_ctr\n");#endif	ctrl->reseted(ctrl);}/******************************Kernel-Capi callback remove_ctr******************************/     void hycapi_remove_ctr(struct capi_ctr *ctrl){	int i;	hycapictrl_info *cinfo = NULL;	hysdn_card *card = NULL;#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "HYCAPI hycapi_remove_ctr\n");#endif 	if(!hy_di) {		printk(KERN_ERR "No capi_driver_interface set!");		return;	}	cinfo = (hycapictrl_info *)(ctrl->driverdata);	if(!cinfo) {		printk(KERN_ERR "No hycapictrl_info set!");		return;	}    	card = cinfo->card;	ctrl->suspend_output(ctrl);	for(i=0; i<CAPI_MAXAPPL;i++) {		if(hycapi_applications[i].listen_req[ctrl->cnr-1]) {			kfree_skb(hycapi_applications[i].listen_req[ctrl->cnr-1]);			hycapi_applications[i].listen_req[ctrl->cnr-1] = NULL;		}	}	hy_di->detach_ctr(ctrl);	ctrl->driverdata = 0;	kfree(card->hyctrlinfo);			card->hyctrlinfo = NULL;}/***********************************************************Queue a CAPI-message to the controller.***********************************************************/static voidhycapi_sendmsg_internal(struct capi_ctr *ctrl, struct sk_buff *skb){	hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);	hysdn_card *card = cinfo->card;	spin_lock_irq(&cinfo->lock);#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "hycapi_send_message\n");    #endif	cinfo->skbs[cinfo->in_idx++] = skb;	/* add to buffer list */	if (cinfo->in_idx >= HYSDN_MAX_CAPI_SKB)		cinfo->in_idx = 0;	/* wrap around */	cinfo->sk_count++;		/* adjust counter */	if (cinfo->sk_count >= HYSDN_MAX_CAPI_SKB) {		/* inform upper layers we're full */		printk(KERN_ERR "HYSDN Card%d: CAPI-buffer overrun!\n",		       card->myid);			ctrl->suspend_output(ctrl);	}	cinfo->tx_skb = skb;	spin_unlock_irq(&cinfo->lock);	queue_task(&card->irq_queue, &tq_immediate);	mark_bh(IMMEDIATE_BH);}/***********************************************************hycapi_register_internalSend down the CAPI_REGISTER-Command to the controller.This functions will also be used if the adapter has been rebooted tore-register any applications in the private list.************************************************************/static void hycapi_register_internal(struct capi_ctr *ctrl, __u16 appl,			 capi_register_params *rp){	char ExtFeatureDefaults[] = "49  /0/0/0/0,*/1,*/2,*/3,*/4,*/5,*/6,*/7,*/8,*/9,*";	hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);	hysdn_card *card = cinfo->card;	struct sk_buff *skb;	__u16 len;	__u8 _command = 0xa0, _subcommand = 0x80;	__u16 MessageNumber = 0x0000;	__u16 MessageBufferSize = 0;	int slen = strlen(ExtFeatureDefaults);#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "hycapi_register_appl\n"); #endif	MessageBufferSize = rp->level3cnt * rp->datablkcnt * rp->datablklen; 	len = CAPI_MSG_BASELEN + 8 + slen + 1;	if (!(skb = alloc_skb(len, GFP_ATOMIC))) {		printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",		       card->myid);		return;	}	memcpy(skb_put(skb,sizeof(__u16)), &len, sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u16)), &appl, sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u8)), &_command, sizeof(_command));	memcpy(skb_put(skb,sizeof(__u8)), &_subcommand, sizeof(_subcommand));	memcpy(skb_put(skb,sizeof(__u16)), &MessageNumber, sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u16)), &MessageBufferSize, sizeof(__u16)); 	memcpy(skb_put(skb,sizeof(__u16)), &(rp->level3cnt), sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u16)), &(rp->datablkcnt), sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u16)), &(rp->datablklen), sizeof(__u16));	memcpy(skb_put(skb,slen), ExtFeatureDefaults, slen);	hycapi_applications[appl-1].ctrl_mask |= (1 << (ctrl->cnr-1));    	hycapi_send_message(ctrl, skb);    }/************************************************************hycapi_restart_internalAfter an adapter has been rebootet, re-register all applications andsend a LISTEN_REQ (if there has been such a thing )*************************************************************/static void hycapi_restart_internal(struct capi_ctr *ctrl){	int i;	struct sk_buff *skb;#ifdef HYCAPI_PRINTFNAMES	printk(KERN_WARNING "HYSDN: hycapi_restart_internal");#endif	for(i=0; i<CAPI_MAXAPPL; i++) {		if(_hycapi_appCheck(i+1, ctrl->cnr) == 1) {			hycapi_register_internal(ctrl, i+1, 						 &hycapi_applications[i].rp);			if(hycapi_applications[i].listen_req[ctrl->cnr-1]) {				skb = skb_copy(hycapi_applications[i].listen_req[ctrl->cnr-1], GFP_ATOMIC);				hycapi_sendmsg_internal(ctrl, skb);			}		}	}}/*************************************************************Register an application.Error-checking is done for CAPI-compliance.The application is recorded in the internal list.*************************************************************/void hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl, 		     capi_register_params *rp){	int MaxLogicalConnections = 0, MaxBDataBlocks = 0, MaxBDataLen = 0;	hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);	hysdn_card *card = cinfo->card;	int chk = _hycapi_appCheck(appl, ctrl->cnr);	if(chk < 0) {		return;	}	if(chk == 1) {		printk(KERN_INFO "HYSDN: apl %d allready registered\n", appl);		return;	}	MaxBDataBlocks = rp->datablkcnt > CAPI_MAXDATAWINDOW ? CAPI_MAXDATAWINDOW : rp->datablkcnt;	rp->datablkcnt = MaxBDataBlocks;	MaxBDataLen = rp->datablklen < 1024 ? 1024 : rp->datablklen ;	rp->datablklen = MaxBDataLen;		MaxLogicalConnections = rp->level3cnt;	if (MaxLogicalConnections < 0) {		MaxLogicalConnections = card->bchans * -MaxLogicalConnections; 	}	if (MaxLogicalConnections == 0) {		MaxLogicalConnections = card->bchans;	}		rp->level3cnt = MaxLogicalConnections;	memcpy(&hycapi_applications[appl-1].rp, 	       rp, sizeof(capi_register_params));	/*        MOD_INC_USE_COUNT; */	ctrl->appl_registered(ctrl, appl);}/*********************************************************************hycapi_release_internalSend down a CAPI_RELEASE to the controller.*********************************************************************/static void hycapi_release_internal(struct capi_ctr *ctrl, __u16 appl){	hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);	hysdn_card *card = cinfo->card;	struct sk_buff *skb;	__u16 len;	__u8 _command = 0xa1, _subcommand = 0x80;	__u16 MessageNumber = 0x0000;#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "hycapi_release_appl\n");#endif	len = CAPI_MSG_BASELEN;	if (!(skb = alloc_skb(len, GFP_ATOMIC))) {		printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",		       card->myid);		return;	}	memcpy(skb_put(skb,sizeof(__u16)), &len, sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u16)), &appl, sizeof(__u16));	memcpy(skb_put(skb,sizeof(__u8)), &_command, sizeof(_command));	memcpy(skb_put(skb,sizeof(__u8)), &_subcommand, sizeof(_subcommand));	memcpy(skb_put(skb,sizeof(__u16)), &MessageNumber, sizeof(__u16));    	hycapi_send_message(ctrl, skb);    	hycapi_applications[appl-1].ctrl_mask &= ~(1 << (ctrl->cnr-1));    }/******************************************************************hycapi_release_applRelease the application from the internal list an remove it's registration at controller-level******************************************************************/void hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl){	int chk;	chk = _hycapi_appCheck(appl, ctrl->cnr);	if(chk<0) {		printk(KERN_ERR "HYCAPI: Releasing invalid appl %d on controller %d\n", appl, ctrl->cnr);		return;	}	if(hycapi_applications[appl-1].listen_req[ctrl->cnr-1]) {		kfree_skb(hycapi_applications[appl-1].listen_req[ctrl->cnr-1]);		hycapi_applications[appl-1].listen_req[ctrl->cnr-1] = NULL;	}	if(chk == 1)	{		hycapi_release_internal(ctrl, appl);	}	ctrl->appl_released(ctrl, appl);/*        MOD_DEC_USE_COUNT;  */}/**************************************************************Kill a single controller.**************************************************************/int hycapi_capi_release(hysdn_card *card){	hycapictrl_info *cinfo = card->hyctrlinfo;	struct capi_ctr *ctrl;#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "hycapi_capi_release\n");#endif	if(cinfo) {		ctrl = cinfo->capi_ctrl;		hycapi_remove_ctr(ctrl);	}	return 0;}/**************************************************************hycapi_capi_stopStop CAPI-Output on a card. (e.g. during reboot)***************************************************************/int hycapi_capi_stop(hysdn_card *card){	hycapictrl_info *cinfo = card->hyctrlinfo;	struct capi_ctr *ctrl;#ifdef HYCAPI_PRINTFNAMES	printk(KERN_NOTICE "hycapi_capi_stop\n");#endif	if(cinfo) {		if(cinfo->capi_ctrl) {			ctrl = cinfo->capi_ctrl;/*			ctrl->suspend_output(ctrl); */			ctrl->reseted(ctrl);		} else {			printk(KERN_NOTICE "hycapi_capi_stop: cinfo but no capi_ctrl\n");		}	}	return 0;}/***************************************************************hycapi_send_messageSend a message to the controller.Messages are parsed for their Command/Subcommand-type, and appropriateaction's are performed.Note that we have to muck around with a 64Bit-DATA_REQ as there arefirmware-releases that do not check the MsgLen-Indication!***************************************************************/void hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb){	__u16 appl_id;	int _len, _len2;	__u8 msghead[64];		appl_id = CAPIMSG_APPID(skb->data);	switch(_hycapi_appCheck(appl_id, ctrl->cnr))	{		case 0:/*			printk(KERN_INFO "Need to register\n"); */			hycapi_register_internal(ctrl, 						 appl_id,						 &(hycapi_applications[appl_id-1].rp));			break;		case 1:			break;		default:			printk(KERN_ERR "HYCAPI: Controller mixup!\n");			return;	}	switch(CAPIMSG_CMD(skb->data)) {				case CAPI_DISCONNECT_B3_RESP:			ctrl->free_ncci(ctrl, appl_id, 					CAPIMSG_NCCI(skb->data));			break;		case CAPI_DATA_B3_REQ:			_len = CAPIMSG_LEN(skb->data);			if (_len > 22) {				_len2 = _len - 22;				memcpy(msghead, skb->data, 22);				memcpy(skb->data + _len2, msghead, 22);				skb_pull(skb, _len2);				CAPIMSG_SETLEN(skb->data, 22);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -