225 lines
12 KiB
Plaintext
225 lines
12 KiB
Plaintext
<HTML>
|
|
|
|
<!-- Generated by c2html-1.0, Copyright 1998 by Dave Whittington -->
|
|
<HEAD>
|
|
<TITLE>isdn_budget.c</TITLE>
|
|
<!--#include virtual="/ssi/js.shtml" -->
|
|
<!--#include virtual="/ssi/buttondefs.shtml" -->
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF">
|
|
<TABLE WIDTH="100%">
|
|
<TR>
|
|
<TD ALIGN=LEFT WIDTH="90"><!--#include virtual="/ssi/b_home.shtml" --></TD>
|
|
<TD ALIGN=RIGHT WIDTH="90"><!--#include virtual="/ssi/b_index.shtml" --></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<CENTER><H1>isdn_budget.c</H1></CENTER>
|
|
|
|
<HR>
|
|
<PRE>
|
|
<FONT COLOR=#0000FF>/* $Id$
|
|
*
|
|
* Linux ISDN subsystem, budget-accounting for network interfaces.
|
|
*
|
|
* Copyright 1997 by Christian Lademann <cal@zls.de>
|
|
*
|
|
* 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.
|
|
*
|
|
* $Log$
|
|
* Revision 1.2 1998/03/07 23:17:30 fritz
|
|
* Added RCS keywords
|
|
* Bugfix: Did not compile without isdn_dumppkt beeing enabled.
|
|
*
|
|
*/</FONT>
|
|
|
|
<FONT COLOR=#0000FF>/*
|
|
30.06.97:cal:angelegt
|
|
04.11.97:cal:budget.period: int --> time_t
|
|
*/</FONT>
|
|
|
|
<FONT COLOR=#A521F7>#include</FONT> <linux/config.h>
|
|
<FONT COLOR=#A521F7>#define</FONT> <A HREF="isdn_audio.c.shtml#__NO_VERSION__">__NO_VERSION__</A>
|
|
<FONT COLOR=#A521F7>#include</FONT> <linux/module.h>
|
|
<FONT COLOR=#A521F7>#include</FONT> <linux/isdn.h>
|
|
<FONT COLOR=#A521F7>#include</FONT> <FONT COLOR="#FF0000">"isdn_common.h"</FONT>
|
|
<FONT COLOR=#A521F7>#include</FONT> <FONT COLOR="#FF0000">"isdn_net.h"</FONT>
|
|
|
|
<FONT COLOR=#A521F7>#ifdef</FONT> CONFIG_ISDN_BUDGET
|
|
|
|
<FONT COLOR=#A521F7>#define</FONT> <A HREF="#VERBOSE_PRINTK">VERBOSE_PRINTK</A>(v, l, p...) { \
|
|
<FONT COLOR="#298C52">if</FONT>(dev->net_verbose >= (v)) { \
|
|
printk(l ## p); \
|
|
} <FONT COLOR="#298C52">else</FONT> { ; } \
|
|
}
|
|
|
|
|
|
<FONT COLOR="#298C52">int</FONT>
|
|
<A NAME="isdn_net_budget">isdn_net_budget</A>(<FONT COLOR="#298C52">int</FONT> type, <FONT COLOR="#298C52">struct</FONT> device *ndev) {
|
|
isdn_net_local *lp = (isdn_net_local *)ndev->priv;
|
|
<FONT COLOR="#298C52">int</FONT> i, ret = 0;
|
|
|
|
<FONT COLOR="#298C52">switch</FONT>(type) {
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_INIT">ISDN_BUDGET_INIT</A>:
|
|
<FONT COLOR="#298C52">for</FONT>(i = 0; i < <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_NUM_BUDGET">ISDN_BUDGET_NUM_BUDGET</A>; i++) {
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .amount = -1;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .used = 0;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .period = (time_t)0;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .period_started = (time_t)0;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .last_check = CURRENT_TIME;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .notified = 0;
|
|
}
|
|
|
|
<FONT COLOR="#298C52">return</FONT>(0);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHECK_DIAL">ISDN_BUDGET_CHECK_DIAL</A>:
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHECK_CHARGE">ISDN_BUDGET_CHECK_CHARGE</A>:
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHECK_ONLINE">ISDN_BUDGET_CHECK_ONLINE</A>:
|
|
ret = 0;
|
|
|
|
<FONT COLOR="#298C52">for</FONT>(i = 0; i < <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_NUM_BUDGET">ISDN_BUDGET_NUM_BUDGET</A>; i++) {
|
|
<FONT COLOR="#298C52">if</FONT>(lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .amount < 0)
|
|
<FONT COLOR="#298C52">continue</FONT>;
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .period_started + lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .period < CURRENT_TIME) {
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .used = 0;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .period_started = CURRENT_TIME;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .notified = 0;
|
|
}
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .used >= lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .amount)
|
|
ret |= (1 << i);
|
|
}
|
|
|
|
<FONT COLOR="#298C52">switch</FONT>(type) {
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHECK_DIAL">ISDN_BUDGET_CHECK_DIAL</A>:
|
|
<FONT COLOR="#298C52">if</FONT>(! ret) {
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_DIAL">ISDN_BUDGET_DIAL</A>] .used++;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_DIAL">ISDN_BUDGET_DIAL</A>] .last_check = CURRENT_TIME;
|
|
}
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHECK_CHARGE">ISDN_BUDGET_CHECK_CHARGE</A>:
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHARGE">ISDN_BUDGET_CHARGE</A>] .used++;
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHARGE">ISDN_BUDGET_CHARGE</A>] .last_check = CURRENT_TIME;
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHECK_ONLINE">ISDN_BUDGET_CHECK_ONLINE</A>:
|
|
<FONT COLOR="#298C52">if</FONT>(lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_ONLINE">ISDN_BUDGET_ONLINE</A>] .last_check) {
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_ONLINE">ISDN_BUDGET_ONLINE</A>] .used += (CURRENT_TIME - lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_ONLINE">ISDN_BUDGET_ONLINE</A>] .last_check);
|
|
}
|
|
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_ONLINE">ISDN_BUDGET_ONLINE</A>] .last_check = CURRENT_TIME;
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
}
|
|
|
|
<FONT COLOR=#0000FF>/*
|
|
if(ret)
|
|
lp->flags |= ISDN_NET_STOPPED;
|
|
*/</FONT>
|
|
<FONT COLOR="#298C52">for</FONT>(i = 0; i < <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_NUM_BUDGET">ISDN_BUDGET_NUM_BUDGET</A>; i++) {
|
|
<FONT COLOR="#298C52">if</FONT>(ret & (1 << i) && ! lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .notified) {
|
|
<FONT COLOR="#298C52">switch</FONT>(i) {
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_DIAL">ISDN_BUDGET_DIAL</A>:
|
|
printk(KERN_WARNING <FONT COLOR="#FF0000">"isdn_budget: dial budget used up.\n"</FONT>);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_CHARGE">ISDN_BUDGET_CHARGE</A>:
|
|
printk(KERN_WARNING <FONT COLOR="#FF0000">"isdn_budget: charge budget used up.\n"</FONT>);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_ONLINE">ISDN_BUDGET_ONLINE</A>:
|
|
printk(KERN_WARNING <FONT COLOR="#FF0000">"isdn_budget: online budget used up.\n"</FONT>);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">default</FONT>:
|
|
printk(KERN_WARNING <FONT COLOR="#FF0000">"isdn_budget: budget #%d used up.\n"</FONT>, i);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
}
|
|
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [i] .notified = 1;
|
|
}
|
|
}
|
|
|
|
<FONT COLOR="#298C52">return</FONT>(ret);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_START_ONLINE">ISDN_BUDGET_START_ONLINE</A>:
|
|
lp-><A HREF="isdn_common.c.shtml#budget">budget</A> [<A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_ONLINE">ISDN_BUDGET_ONLINE</A>] .last_check = CURRENT_TIME;
|
|
<FONT COLOR="#298C52">return</FONT>(0);
|
|
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
}
|
|
|
|
<FONT COLOR="#298C52">return</FONT>(-1);
|
|
}
|
|
|
|
|
|
<FONT COLOR="#298C52">int</FONT>
|
|
<A NAME="isdn_budget_ioctl">isdn_budget_ioctl</A>(<A HREF="../includes/isdn_budget.h.shtml#isdn_ioctl_budget">isdn_ioctl_budget</A> *iocmd) {
|
|
<A HREF="../includes/isdn.h.shtml#isdn_net_dev">isdn_net_dev</A> *p = <A HREF="isdn_net.c.shtml#isdn_net_findif">isdn_net_findif</A>(iocmd-><A HREF="isdn_common.c.shtml#name">name</A>);
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(p) {
|
|
<FONT COLOR="#298C52">switch</FONT>(iocmd->command) {
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_SET_BUDGET">ISDN_BUDGET_SET_BUDGET</A>:
|
|
<FONT COLOR="#298C52">if</FONT>(! suser())
|
|
<FONT COLOR="#298C52">return</FONT>(-EPERM);
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A> < 0 || iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A> > <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_NUM_BUDGET">ISDN_BUDGET_NUM_BUDGET</A>)
|
|
<FONT COLOR="#298C52">return</FONT>(-EINVAL);
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(iocmd->amount < 0)
|
|
iocmd->amount = -1;
|
|
|
|
p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .amount = iocmd->amount;
|
|
p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .period = iocmd->period;
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(iocmd->used <= 0)
|
|
p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .used = 0;
|
|
<FONT COLOR="#298C52">else</FONT>
|
|
p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .used = iocmd->used;
|
|
|
|
<FONT COLOR="#298C52">if</FONT>(iocmd->period_started == (time_t)0)
|
|
p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .period_started = CURRENT_TIME;
|
|
<FONT COLOR="#298C52">else</FONT>
|
|
p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .period_started = iocmd->period_started;
|
|
|
|
<FONT COLOR="#298C52">return</FONT>(0);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">case</FONT> <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_GET_BUDGET">ISDN_BUDGET_GET_BUDGET</A>:
|
|
<FONT COLOR="#298C52">if</FONT>(iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A> < 0 || iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A> > <A HREF="../includes/isdn_budget.h.shtml#ISDN_BUDGET_NUM_BUDGET">ISDN_BUDGET_NUM_BUDGET</A>)
|
|
<FONT COLOR="#298C52">return</FONT>(-EINVAL);
|
|
|
|
iocmd->amount = p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .amount;
|
|
iocmd->used = p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .used;
|
|
iocmd->period = p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .period;
|
|
iocmd->period_started = p->local-><A HREF="isdn_common.c.shtml#budget">budget</A> [iocmd-><A HREF="isdn_common.c.shtml#budget">budget</A>] .period_started;
|
|
|
|
<FONT COLOR="#298C52">return</FONT>(0);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
|
|
<FONT COLOR="#298C52">default</FONT>:
|
|
<FONT COLOR="#298C52">return</FONT>(-EINVAL);
|
|
<FONT COLOR="#298C52">break</FONT>;
|
|
}
|
|
}
|
|
<FONT COLOR="#298C52">return</FONT>(-ENODEV);
|
|
}
|
|
<FONT COLOR=#A521F7>#endif</FONT>
|
|
</BODY>
|
|
|
|
</HTML>
|