Add functions to allow PCM bus transactions

Signed-off-by: Karsten Keil <kkeil@linux-pingi.de>
This commit is contained in:
Karsten Keil 2011-06-15 10:52:34 +02:00 committed by Karsten Keil
parent 4b4f5931c9
commit afc47ea9d8
3 changed files with 73 additions and 11 deletions

View File

@ -38,7 +38,7 @@
*/
#define MISDN_MAJOR_VERSION 1
#define MISDN_MINOR_VERSION 1
#define MISDN_RELEASE 22
#define MISDN_RELEASE 24
/* primitives for information exchange
* generell format
@ -230,7 +230,7 @@
#define ISDN_P_B_MASK 0x1f
#define ISDN_P_B_START 0x20
#define ISDN_P_B_PCM 0x20
#define ISDN_P_B_RAW 0x21
#define ISDN_P_B_HDLC 0x22
#define ISDN_P_B_X75SLP 0x23
@ -361,8 +361,8 @@ clear_channelmap(u_int nr, u_char *map)
#define MISDN_CTRL_LOOP 0x0001
#define MISDN_CTRL_CONNECT 0x0002
#define MISDN_CTRL_DISCONNECT 0x0004
#define MISDN_CTRL_PCMCONNECT 0x0010
#define MISDN_CTRL_PCMDISCONNECT 0x0020
#define MISDN_CTRL_GET_PCM_SLOTS 0x0010
#define MISDN_CTRL_SET_PCM_SLOTS 0x0020
#define MISDN_CTRL_SETPEER 0x0040
#define MISDN_CTRL_UNSETPEER 0x0080
#define MISDN_CTRL_RX_OFF 0x0100
@ -379,7 +379,12 @@ clear_channelmap(u_int nr, u_char *map)
#define MISDN_CTRL_HFC_RECEIVE_ON 0x4006
#define MISDN_CTRL_HFC_ECHOCAN_ON 0x4007
#define MISDN_CTRL_HFC_ECHOCAN_OFF 0x4008
#define MISDN_CTRL_HFC_WD_INIT 0x4009
#define MISDN_CTRL_HFC_WD_RESET 0x400A
/* special PCM slot numbers */
#define MISDN_PCM_SLOT_DISABLE -1 /* PCM disabled */
#define MISDN_PCM_SLOT_IGNORE -2 /* PCM setting will be not changed */
/* socket options */
#define MISDN_TIME_STAMP 0x0001
@ -389,6 +394,7 @@ struct mISDN_ctrl_req {
int channel;
int p1;
int p2;
int p3;
};
/* muxer options */

View File

@ -22,7 +22,6 @@
extern "C" {
#endif
struct l3_head {
unsigned char type;
unsigned char crlen;
@ -91,13 +90,24 @@ struct mlayer3;
*/
typedef int (mlayer3_cb_t)(struct mlayer3 *, unsigned int, unsigned int, struct l3_msg *);
/*
* To avoid to include always all headers needed for mISDNif.h we redefine MISDN_CHMAP_SIZE here
* Please make sure to keep it in sync with mISDNif.h (but changes are very unlikely)
*/
#ifndef MISDN_CHMAP_SIZE
#define MISDN_MAX_CHANNEL 127
#define MISDN_CHMAP_SIZE ((MISDN_MAX_CHANNEL + 1) >> 3)
#endif
struct mlayer3 {
unsigned int device;
unsigned int nr_bchannel;
unsigned long options;
mlayer3_cb_t *to_layer3;
mlayer3_cb_t *from_layer3;
void *priv; /* free user for applications */
void *priv; /* free use for applications */
unsigned char channelmap[MISDN_CHMAP_SIZE];
};
/*
@ -129,6 +139,7 @@ struct mlayer3 {
#define MT_FREE 0x1001
#define MT_L2ESTABLISH 0x2000
#define MT_L2RELEASE 0x2001
#define MT_L2IDLE 0x2002
#define MT_ERROR 0x8000
#define MT_TIMEOUT 0x8001
@ -139,6 +150,7 @@ struct mlayer3 {
*/
#define MISDN_PID_DUMMY 0x81000000
#define MISDN_PID_GLOBAL 0x82000000
#define MISDN_PID_NONE 0xFFFFFFFF
#define MISDN_PID_MASTER 0xFF000000
#define MISDN_PID_CRTYPE_MASK 0xFF000000
#define MISDN_PID_CID_MASK 0x00FF0000
@ -162,11 +174,11 @@ extern void cleanup_layer3(void);
/*
* open a layer3 stack
* parameter1 - device id
* parameter2 - protocol
* parameter3 - layer3 additional properties
* parameter4 - callback function to deliver messages
* parameter5 - pointer for private application use
* @parameter1 - device id
* @parameter2 - protocol
* @parameter3 - layer3 additional properties
* @parameter4 - callback function to deliver messages
* @parameter5 - pointer for private application use
*/
extern struct mlayer3 *open_layer3(unsigned int, unsigned int, unsigned int, mlayer3_cb_t *, void *);
@ -177,6 +189,8 @@ extern struct mlayer3 *open_layer3(unsigned int, unsigned int, unsigned int, mla
extern void close_layer3(struct mlayer3 *);
extern unsigned int request_new_pid(struct mlayer3 *);
extern int mISDN_get_pcm_slots(struct mlayer3 *, int, int *, int *);
extern int mISDN_set_pcm_slots(struct mlayer3 *, int, int, int);
extern struct l3_msg *alloc_l3_msg(void);
extern void free_l3_msg(struct l3_msg *);
extern int add_layer3_ie(struct l3_msg *, unsigned char, int, unsigned char *);

View File

@ -110,6 +110,7 @@ open_layer3(unsigned int dev, unsigned int proto, unsigned int prop, mlayer3_cb_
}
close(fd);
l3->ml3.nr_bchannel = devinfo.nrbchan;
memcpy(l3->ml3.channelmap, devinfo.channelmap, MISDN_CHMAP_SIZE);
if (!(devinfo.Dprotocols & (1 << ISDN_P_TE_E1))
&& !(devinfo.Dprotocols & (1 << ISDN_P_NT_E1)))
test_and_set_bit(FLG_BASICRATE, &l3->ml3.options);
@ -219,3 +220,44 @@ close_layer3(struct mlayer3 *ml3)
free(l3);
}
int
mISDN_set_pcm_slots(struct mlayer3 *ml3, int channel, int tx, int rx)
{
struct _layer3 *l3;
struct mISDN_ctrl_req ctrlrq;
int ret;
ctrlrq.op = MISDN_CTRL_SET_PCM_SLOTS;
ctrlrq.channel = 0; /* via D-channel */
ctrlrq.p1 = channel;
ctrlrq.p2 = tx;
ctrlrq.p3 = rx;
l3 = container_of(ml3, struct _layer3, ml3);
ret = ioctl(l3->l2sock, IMCTRLREQ, &ctrlrq);
if (ret < 0)
fprintf(stderr, "could not send IOCTL IMCTRLREQ %s\n", strerror(errno));
return ret;
}
int
mISDN_get_pcm_slots(struct mlayer3 *ml3, int channel, int *txp, int *rxp)
{
struct _layer3 *l3;
struct mISDN_ctrl_req ctrlrq;
int ret;
ctrlrq.op = MISDN_CTRL_GET_PCM_SLOTS;
ctrlrq.channel = 0; /* via D-channel */
ctrlrq.p1 = channel;
l3 = container_of(ml3, struct _layer3, ml3);
ret = ioctl(l3->l2sock, IMCTRLREQ, &ctrlrq);
if (ret < 0)
fprintf(stderr, "could not send IOCTL IMCTRLREQ %s\n", strerror(errno));
else {
if (txp)
*txp = ctrlrq.p2;
if (rxp)
*rxp = ctrlrq.p3;
}
return ret;
}