Commit 80a78a60 authored by Kai Germaschewski's avatar Kai Germaschewski

ISDN: Move generic bits from isdn_net_lib to isdn_common

o When accepting an incoming call, leave it to the common code to set
  usage, numbers etc.
o Make USAGE_EXCLUSIVE just another flag when getting / accepting 
  a channel, getting rid of some special case code.
o No need to pass the current usage when freeing a channel
parent 25977f14
...@@ -503,11 +503,14 @@ isdn_status_callback(isdn_ctrl * c) ...@@ -503,11 +503,14 @@ isdn_status_callback(isdn_ctrl * c)
retval = 2; retval = 2;
} }
break; break;
case 1: case 1: /* incoming call accepted by net interface */
list_for_each(l, &isdn_net_devs) { list_for_each(l, &isdn_net_devs) {
isdn_net_dev *p = list_entry(l, isdn_net_dev, global_list); isdn_net_dev *p = list_entry(l, isdn_net_dev, global_list);
if (p->isdn_slot == i) { if (p->isdn_slot == i) {
strcpy(cmd.parm.setup.eazmsn, p->mlp->msn); strcpy(cmd.parm.setup.eazmsn, p->mlp->msn);
isdn_slot_set_usage(i, (isdn_slot_usage(i) & ISDN_USAGE_EXCLUSIVE) | ISDN_USAGE_NET);
strcpy(isdn_slot_num(i), c->parm.setup.phone);
isdn_slot_command(i, ISDN_CMD_ACCEPTD, &cmd); isdn_slot_command(i, ISDN_CMD_ACCEPTD, &cmd);
retval = 1; retval = 1;
break; break;
...@@ -1535,26 +1538,20 @@ isdn_get_free_slot(int usage, int l2_proto, int l3_proto, ...@@ -1535,26 +1538,20 @@ isdn_get_free_slot(int usage, int l2_proto, int l3_proto,
if (USG_NONE(slot[i].usage) && if (USG_NONE(slot[i].usage) &&
(slot[i].di != -1)) { (slot[i].di != -1)) {
int d = slot[i].di; int d = slot[i].di;
if ((slot[i].usage & ISDN_USAGE_EXCLUSIVE) &&
((pre_dev != d) || (pre_chan != slot[i].ch)))
continue;
if (!strcmp(isdn_map_eaz2msn(msn, d), "-")) if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
continue; continue;
if (slot[i].usage & ISDN_USAGE_DISABLED) if (slot[i].usage & ISDN_USAGE_DISABLED)
continue; /* usage not allowed */ continue; /* usage not allowed */
if (dev->drv[d]->flags & DRV_FLAG_RUNNING) { if (!dev->drv[d]->flags & DRV_FLAG_RUNNING)
continue;
if (((dev->drv[d]->interface->features & features) == features) || if (((dev->drv[d]->interface->features & features) == features) ||
(((dev->drv[d]->interface->features & vfeatures) == vfeatures) && (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
(dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) { (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
if ((pre_dev < 0) || (pre_chan < 0)) { if (pre_dev < 0 || pre_chan < 0 ||
isdn_slot_set_usage(i, (isdn_slot_usage(i) & ISDN_USAGE_EXCLUSIVE) | usage); (pre_dev == d && pre_chan == slot[i].ch)) {
isdn_slot_set_usage(i, usage);
restore_flags(flags); restore_flags(flags);
return i; return i;
} else if ((pre_dev == d) && (pre_chan == slot[i].ch)) {
isdn_slot_set_usage(i, (isdn_slot_usage(i) & ISDN_USAGE_EXCLUSIVE) | usage);
restore_flags(flags);
return i;
}
} }
} }
} }
...@@ -1571,17 +1568,16 @@ isdn_free_channel(int di, int ch, int usage) ...@@ -1571,17 +1568,16 @@ isdn_free_channel(int di, int ch, int usage)
int sl; int sl;
sl = isdn_dc2minor(di, ch); sl = isdn_dc2minor(di, ch);
isdn_slot_free(sl, usage); isdn_slot_free(sl);
} }
void void
isdn_slot_free(int sl, int usage) isdn_slot_free(int sl)
{ {
unsigned long flags; unsigned long flags;
save_flags(flags); save_flags(flags);
cli(); cli();
if (!usage || (slot[sl].usage & ISDN_USAGE_MASK) == usage) {
strcpy(isdn_slot_num(sl), "???"); strcpy(isdn_slot_num(sl), "???");
slot[sl].ibytes = 0; slot[sl].ibytes = 0;
slot[sl].obytes = 0; slot[sl].obytes = 0;
...@@ -1591,30 +1587,8 @@ isdn_slot_free(int sl, int usage) ...@@ -1591,30 +1587,8 @@ isdn_slot_free(int sl, int usage)
isdn_v110_close(slot[sl].iv110.v110); isdn_v110_close(slot[sl].iv110.v110);
slot[sl].iv110.v110 = NULL; slot[sl].iv110.v110 = NULL;
// 20.10.99 JIM, try to reinitialize v110 ! // 20.10.99 JIM, try to reinitialize v110 !
isdn_slot_set_usage(sl, isdn_slot_usage(sl) & (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE)); isdn_slot_set_usage(sl, ISDN_USAGE_NONE);
skb_queue_purge(&dev->drv[isdn_slot_driver(sl)]->rpqueue[isdn_slot_channel(sl)]); skb_queue_purge(&dev->drv[isdn_slot_driver(sl)]->rpqueue[isdn_slot_channel(sl)]);
}
restore_flags(flags);
}
/*
* Cancel Exclusive-Flag for ISDN-channel
*/
void
isdn_unexclusive_channel(int di, int ch)
{
int i;
ulong flags;
save_flags(flags);
cli();
for (i = 0; i < ISDN_MAX_CHANNELS; i++)
if ((slot[i].di == di) &&
(slot[i].ch == ch)) {
isdn_slot_set_usage(i, isdn_slot_usage(i) & ~ISDN_USAGE_EXCLUSIVE);
restore_flags(flags);
return;
}
restore_flags(flags); restore_flags(flags);
} }
...@@ -1959,6 +1933,7 @@ isdn_slot_command(int sl, int cmd, isdn_ctrl *ctrl) ...@@ -1959,6 +1933,7 @@ isdn_slot_command(int sl, int cmd, isdn_ctrl *ctrl)
case ISDN_CMD_DIAL: case ISDN_CMD_DIAL:
if (dev->global_flags & ISDN_GLOBAL_STOPPED) if (dev->global_flags & ISDN_GLOBAL_STOPPED)
return -EBUSY; return -EBUSY;
/* fall through */ /* fall through */
default: default:
ctrl->arg = isdn_slot_channel(sl); ctrl->arg = isdn_slot_channel(sl);
......
...@@ -64,7 +64,6 @@ extern int isdn_dc2minor(int di, int ch); ...@@ -64,7 +64,6 @@ extern int isdn_dc2minor(int di, int ch);
extern void isdn_info_update(void); extern void isdn_info_update(void);
extern char *isdn_map_eaz2msn(char *msn, int di); extern char *isdn_map_eaz2msn(char *msn, int di);
extern void isdn_timer_ctrl(int tf, int onoff); extern void isdn_timer_ctrl(int tf, int onoff);
extern void isdn_unexclusive_channel(int di, int ch);
extern int isdn_getnum(char **); extern int isdn_getnum(char **);
extern int isdn_msncmp( const char *, const char *); extern int isdn_msncmp( const char *, const char *);
extern int isdn_add_channels(driver *, int, int, int); extern int isdn_add_channels(driver *, int, int, int);
...@@ -85,7 +84,7 @@ struct dial_info { ...@@ -85,7 +84,7 @@ struct dial_info {
}; };
extern int isdn_get_free_slot(int, int, int, int, int, char *); extern int isdn_get_free_slot(int, int, int, int, int, char *);
extern void isdn_slot_free(int slot, int usage); extern void isdn_slot_free(int slot);
extern void isdn_slot_all_eaz(int slot); extern void isdn_slot_all_eaz(int slot);
extern int isdn_slot_command(int slot, int cmd, isdn_ctrl *); extern int isdn_slot_command(int slot, int cmd, isdn_ctrl *);
extern int isdn_slot_dial(int slot, struct dial_info *dial); extern int isdn_slot_dial(int slot, struct dial_info *dial);
......
...@@ -256,21 +256,18 @@ isdn_net_bind(isdn_net_dev *idev, isdn_net_ioctl_cfg *cfg) ...@@ -256,21 +256,18 @@ isdn_net_bind(isdn_net_dev *idev, isdn_net_ioctl_cfg *cfg)
goto out; goto out;
} }
if (idev->exclusive >= 0) { if (idev->exclusive >= 0) {
isdn_unexclusive_channel(idev->pre_device, idev->pre_channel); isdn_slot_free(idev->exclusive);
isdn_free_channel(idev->pre_device, idev->pre_channel, ISDN_USAGE_NET);
idev->exclusive = -1; idev->exclusive = -1;
} }
if (cfg->exclusive) { if (cfg->exclusive) {
/* If binding is exclusive, try to grab the channel */ /* If binding is exclusive, try to grab the channel */
idev->exclusive = isdn_get_free_slot(ISDN_USAGE_NET, mlp->l2_proto, idev->exclusive = isdn_get_free_slot(ISDN_USAGE_NET | ISDN_USAGE_EXCLUSIVE,
mlp->l3_proto, drvidx, chidx, cfg->eaz); mlp->l2_proto, mlp->l3_proto, drvidx, chidx, cfg->eaz);
if (idev->exclusive < 0) { if (idev->exclusive < 0) {
/* Grab failed, because desired channel is in use */ /* Grab failed, because desired channel is in use */
retval = -EBUSY; retval = -EBUSY;
goto out; goto out;
} }
/* All went ok, so update isdninfo */
isdn_slot_set_usage(idev->exclusive, ISDN_USAGE_EXCLUSIVE);
} }
idev->pre_device = drvidx; idev->pre_device = drvidx;
idev->pre_channel = chidx; idev->pre_channel = chidx;
...@@ -449,7 +446,7 @@ isdn_net_dev_delete(isdn_net_dev *idev) ...@@ -449,7 +446,7 @@ isdn_net_dev_delete(isdn_net_dev *idev)
isdn_net_rmallphone(idev); isdn_net_rmallphone(idev);
if (idev->exclusive >= 0) if (idev->exclusive >= 0)
isdn_unexclusive_channel(idev->pre_device, idev->pre_channel); isdn_free_slot(idev->exclusive);
list_del(&idev->slaves); list_del(&idev->slaves);
...@@ -1209,7 +1206,7 @@ isdn_net_unbind_channel(isdn_net_dev *idev) ...@@ -1209,7 +1206,7 @@ isdn_net_unbind_channel(isdn_net_dev *idev)
fsm_change_state(&idev->fi, ST_NULL); fsm_change_state(&idev->fi, ST_NULL);
isdn_slot_set_idev(idev->isdn_slot, NULL); isdn_slot_set_idev(idev->isdn_slot, NULL);
isdn_slot_free(idev->isdn_slot, ISDN_USAGE_NET); isdn_slot_free(idev->isdn_slot);
idev->isdn_slot = -1; idev->isdn_slot = -1;
...@@ -1234,8 +1231,6 @@ isdn_net_dial(isdn_net_dev *idev) ...@@ -1234,8 +1231,6 @@ isdn_net_dial(isdn_net_dev *idev)
if (slot < 0) if (slot < 0)
goto err; goto err;
isdn_slot_set_usage(slot, isdn_slot_usage(slot) | ISDN_USAGE_OUTGOING);
if (isdn_net_bind_channel(idev, slot) < 0) if (isdn_net_bind_channel(idev, slot) < 0)
goto err; goto err;
...@@ -1257,8 +1252,6 @@ accept_icall(struct fsm_inst *fi, int pr, void *arg) ...@@ -1257,8 +1252,6 @@ accept_icall(struct fsm_inst *fi, int pr, void *arg)
int slot = (int) arg; int slot = (int) arg;
// FIXME this really should be done in generic code // FIXME this really should be done in generic code
// strcpy(isdn_slot_num(slot), nr);
isdn_slot_set_usage(slot, (isdn_slot_usage(slot) & ISDN_USAGE_EXCLUSIVE) | ISDN_USAGE_NET);
isdn_net_bind_channel(idev, slot); isdn_net_bind_channel(idev, slot);
...@@ -1300,8 +1293,6 @@ do_callback(struct fsm_inst *fi, int pr, void *arg) ...@@ -1300,8 +1293,6 @@ do_callback(struct fsm_inst *fi, int pr, void *arg)
if (slot < 0) if (slot < 0)
goto err; goto err;
isdn_slot_set_usage(slot, isdn_slot_usage(slot) | ISDN_USAGE_OUTGOING);
if (isdn_net_bind_channel(idev, slot) < 0) if (isdn_net_bind_channel(idev, slot) < 0)
goto err; goto err;
......
...@@ -745,7 +745,7 @@ isdn_tty_modem_hup(modem_info * info, int local) ...@@ -745,7 +745,7 @@ isdn_tty_modem_hup(modem_info * info, int local)
isdn_slot_all_eaz(slot); isdn_slot_all_eaz(slot);
info->emu.mdmreg[REG_RINGCNT] = 0; info->emu.mdmreg[REG_RINGCNT] = 0;
isdn_slot_free(slot, 0); isdn_slot_free(slot);
isdn_slot_set_m_idx(slot, -1); isdn_slot_set_m_idx(slot, -1);
info->isdn_slot = -1; info->isdn_slot = -1;
} }
......
...@@ -382,7 +382,7 @@ isdn_tty_cmd_FCLASS1(char **p, modem_info * info) ...@@ -382,7 +382,7 @@ isdn_tty_cmd_FCLASS1(char **p, modem_info * info)
info->isdn_slot = i; info->isdn_slot = i;
isdn_slot_set_m_idx(i, info->line); isdn_slot_set_m_idx(i, info->line);
isdn_slot_command(info->isdn_slot, ISDN_CMD_FAXCMD, &c); isdn_slot_command(info->isdn_slot, ISDN_CMD_FAXCMD, &c);
isdn_slot_free(info->isdn_slot, ISDN_USAGE_FAX); isdn_slot_free(info->isdn_slot);
isdn_slot_set_m_idx(i, -1); isdn_slot_set_m_idx(i, -1);
info->isdn_slot = -1; info->isdn_slot = -1;
restore_flags(flags); restore_flags(flags);
......
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