Commit f31b5ddd authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN: Make the state machine explicit

Add a finite state machine helper module, which is basically copied over
from the hisax driver with a little bit of beautification.

Eventually, all ISDN should be converted to using these routines.
parent 4e339dac
...@@ -12,6 +12,7 @@ obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o ...@@ -12,6 +12,7 @@ obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o
# Multipart objects. # Multipart objects.
isdn-objs := isdn_net.o isdn_net_lib.o \ isdn-objs := isdn_net.o isdn_net_lib.o \
isdn_fsm.o \
isdn_ciscohdlck.o \ isdn_ciscohdlck.o \
isdn_tty.o isdn_v110.o \ isdn_tty.o isdn_v110.o \
isdn_common.o \ isdn_common.o \
......
/* $Id: fsm.c,v 1.14.6.4 2001/09/23 22:24:47 kai Exp $
*
* Finite state machine
*
* Author Karsten Keil
* Copyright by Karsten Keil <keil@isdn4linux.de>
* by Kai Germaschewski <kai.germaschewski@gmx.de>
*
* This software may be used and distributed according to the terms
* of the GNU General Public License, incorporated herein by reference.
*
* Thanks to Jan den Ouden
* Fritz Elfert
*
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include "isdn_fsm.h"
int
fsm_new(struct fsm *fsm)
{
int i;
int size = sizeof(fsm_fn) * fsm->st_cnt * fsm->ev_cnt;
fsm->jumpmatrix = kmalloc(size, GFP_KERNEL);
if (!fsm->jumpmatrix)
return -ENOMEM;
memset(fsm->jumpmatrix, 0, size);
for (i = 0; i < fsm->fn_cnt; i++) {
if (fsm->fn_tbl[i].st >= fsm->st_cnt ||
fsm->fn_tbl[i].ev >= fsm->ev_cnt) {
printk(KERN_ERR "FsmNew Error line %d st(%d/%d) ev(%d/%d)\n", i,
fsm->fn_tbl[i].st, fsm->st_cnt,
fsm->fn_tbl[i].ev, fsm->ev_cnt);
continue;
}
fsm->jumpmatrix[fsm->st_cnt * fsm->fn_tbl[i].ev + fsm->fn_tbl[i].st] = fsm->fn_tbl[i].routine;
}
return 0;
}
void
fsm_free(struct fsm *fsm)
{
kfree(fsm->jumpmatrix);
}
int
fsm_event(struct fsm_inst *fi, int event, void *arg)
{
fsm_fn fn;
if (fi->state >= fi->fsm->st_cnt ||
event >= fi->fsm->ev_cnt) {
printk(KERN_ERR "FsmEvent Error st(%d/%d) ev(%d/%d)\n",
fi->state, fi->fsm->st_cnt,event,
fi->fsm->ev_cnt);
return -EINVAL;
}
fn = fi->fsm->jumpmatrix[fi->fsm->st_cnt * event + fi->state];
if (!fn) {
if (fi->debug)
fi->printdebug(fi, "State %s Event %s no routine",
fi->fsm->st_str[fi->state],
fi->fsm->ev_str[event]);
return -ESRCH;
}
if (fi->debug)
fi->printdebug(fi, "State %s Event %s",
fi->fsm->st_str[fi->state],
fi->fsm->ev_str[event]);
fn(fi, event, arg);
return 0;
}
void
fsm_change_state(struct fsm_inst *fi, int newstate)
{
fi->state = newstate;
if (fi->debug)
fi->printdebug(fi, "ChangeState %s",
fi->fsm->st_str[newstate]);
}
#if 0
static void
FsmExpireTimer(struct FsmTimer *ft)
{
#if FSM_TIMER_DEBUG
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "FsmExpireTimer %lx", (long) ft);
#endif
FsmEvent(ft->fi, ft->event, ft->arg);
}
void
FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft)
{
ft->fi = fi;
ft->tl.function = (void *) FsmExpireTimer;
ft->tl.data = (long) ft;
#if FSM_TIMER_DEBUG
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "FsmInitTimer %lx", (long) ft);
#endif
init_timer(&ft->tl);
}
void
FsmDelTimer(struct FsmTimer *ft, int where)
{
#if FSM_TIMER_DEBUG
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "FsmDelTimer %lx %d", (long) ft, where);
#endif
del_timer(&ft->tl);
}
int
FsmAddTimer(struct FsmTimer *ft,
int millisec, int event, void *arg, int where)
{
#if FSM_TIMER_DEBUG
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "FsmAddTimer %lx %d %d",
(long) ft, millisec, where);
#endif
if (timer_pending(&ft->tl)) {
printk(KERN_WARNING "FsmAddTimer: timer already active!\n");
ft->fi->printdebug(ft->fi, "FsmAddTimer already active!");
return -1;
}
init_timer(&ft->tl);
ft->event = event;
ft->arg = arg;
ft->tl.expires = jiffies + (millisec * HZ) / 1000;
add_timer(&ft->tl);
return 0;
}
void
FsmRestartTimer(struct FsmTimer *ft,
int millisec, int event, void *arg, int where)
{
#if FSM_TIMER_DEBUG
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "FsmRestartTimer %lx %d %d",
(long) ft, millisec, where);
#endif
if (timer_pending(&ft->tl))
del_timer(&ft->tl);
init_timer(&ft->tl);
ft->event = event;
ft->arg = arg;
ft->tl.expires = jiffies + (millisec * HZ) / 1000;
add_timer(&ft->tl);
}
#endif
/* $Id: fsm.h,v 1.3.2.2 2001/09/23 22:24:47 kai Exp $
*
* Finite state machine
*
* Author Karsten Keil
* Copyright by Karsten Keil <keil@isdn4linux.de>
* by Kai Germaschewski <kai.germaschewski@gmx.de>
*
* This software may be used and distributed according to the terms
* of the GNU General Public License, incorporated herein by reference.
*
*/
#ifndef __FSM_H__
#define __FSM_H__
#include <linux/timer.h>
struct fsm_inst;
typedef void (*fsm_fn)(struct fsm_inst *, int, void *);
struct fsm {
fsm_fn *jumpmatrix;
int st_cnt, ev_cnt, fn_cnt;
char **st_str, **ev_str;
struct fsm_node *fn_tbl;
};
struct fsm_inst {
struct fsm *fsm;
int state;
int debug;
void *userdata;
int userint;
void (*printdebug) (struct fsm_inst *, char *, ...);
};
struct fsm_node {
int st, ev;
void (*routine) (struct fsm_inst *, int, void *);
};
struct fsm_timer {
struct fsm_inst *fi;
struct timer_list tl;
int ev;
void *arg;
};
int fsm_new(struct fsm *fsm);
void fsm_free(struct fsm *fsm);
int fsm_event(struct fsm_inst *fi, int event, void *arg);
void fsm_change_state(struct fsm_inst *fi, int newstate);
void fsm_init_timer(struct fsm_inst *fi, struct fsm_timer *ft);
int fsm_add_timer(struct fsm_timer *ft, int timeout, int event);
void fsm_mod_timer(struct fsm_timer *ft, int timeout, int event);
void fsm_del_timer(struct fsm_timer *ft);
#endif
...@@ -163,25 +163,6 @@ isdn_net_unreachable(struct net_device *dev, struct sk_buff *skb, char *reason) ...@@ -163,25 +163,6 @@ isdn_net_unreachable(struct net_device *dev, struct sk_buff *skb, char *reason)
dst_link_failure(skb); dst_link_failure(skb);
} }
/*
* Handle status-messages from ISDN-interfacecard.
* This function is called from within the main-status-dispatcher
* isdn_status_callback, which itself is called from the low-level driver.
* Return: 1 = Event handled, 0 = not for us or unknown Event.
*/
int
isdn_net_stat_callback(int idx, isdn_ctrl *c)
{
isdn_net_dev *idev = isdn_slot_idev(idx);
if (!idev) {
HERE;
return 0;
}
return isdn_net_handle_event(idev, c->command, c);
}
static void static void
isdn_net_log_skb(struct sk_buff *skb, isdn_net_dev *idev) isdn_net_log_skb(struct sk_buff *skb, isdn_net_dev *idev)
{ {
...@@ -510,7 +491,7 @@ isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup) ...@@ -510,7 +491,7 @@ isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
/* check acceptable call types for DOV */ /* check acceptable call types for DOV */
dbg_net_icall("n_fi: if='%s', l.msn=%s, l.flags=%#x, l.dstate=%d\n", dbg_net_icall("n_fi: if='%s', l.msn=%s, l.flags=%#x, l.dstate=%d\n",
idev->name, mlp->msn, mlp->flags, idev->dialstate); idev->name, mlp->msn, mlp->flags, idev->fi.state);
my_eaz = isdn_slot_map_eaz2msn(slot, mlp->msn); my_eaz = isdn_slot_map_eaz2msn(slot, mlp->msn);
if (si1 == 1) { /* it's a DOV call, check if we allow it */ if (si1 == 1) { /* it's a DOV call, check if we allow it */
...@@ -768,4 +749,7 @@ isdn_net_init(void) ...@@ -768,4 +749,7 @@ isdn_net_init(void)
#ifdef CONFIG_ISDN_PPP #ifdef CONFIG_ISDN_PPP
register_isdn_netif(ISDN_NET_ENCAP_SYNCPPP, &isdn_ppp_ops); register_isdn_netif(ISDN_NET_ENCAP_SYNCPPP, &isdn_ppp_ops);
#endif #endif
isdn_net_lib_init();
} }
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
extern void isdn_net_init(void); extern void isdn_net_init(void);
extern void isdn_net_exit(void); extern void isdn_net_exit(void);
extern void isdn_net_lib_init(void);
extern void isdn_net_lib_exit(void);
extern void isdn_net_hangup_all(void); extern void isdn_net_hangup_all(void);
extern int isdn_net_ioctl(struct inode *, struct file *, uint, ulong); extern int isdn_net_ioctl(struct inode *, struct file *, uint, ulong);
......
This diff is collapsed.
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include <linux/ioctl.h> #include <linux/ioctl.h>
// FIXME!!!
#include <../drivers/isdn/i4l/isdn_fsm.h>
#ifdef CONFIG_COBALT_MICRO_SERVER #ifdef CONFIG_COBALT_MICRO_SERVER
/* Save memory */ /* Save memory */
#define ISDN_MAX_DRIVERS 2 #define ISDN_MAX_DRIVERS 2
...@@ -367,8 +370,8 @@ typedef struct isdn_net_dev_s { ...@@ -367,8 +370,8 @@ typedef struct isdn_net_dev_s {
int exclusive; /* -1 if non excl./idx to excl chan */ int exclusive; /* -1 if non excl./idx to excl chan */
struct timer_list dial_timer; /* dial events timer */ struct timer_list dial_timer; /* dial events timer */
struct fsm_inst fi; /* call control state machine */
int dial_event; /* event in case of timer expiry */ int dial_event; /* event in case of timer expiry */
int dialstate; /* State for dialing */
int dial; /* # of phone number just dialed */ int dial; /* # of phone number just dialed */
int outgoing; /* Flag: outgoing call */ int outgoing; /* Flag: outgoing call */
int dialretry; /* Counter for Dialout-retries */ int dialretry; /* Counter for Dialout-retries */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment