Wednesday, August 13, 2008

Training for Ankit (3)

The zap driver:

1. Used wcfxo.c as the datum

2. Created the following dummy functions
wcfxo_open
wcfxo_close
wcfxo_read
wcfxo_write
wcfxo_hooksig

3. Made the hello_spaninit function to initialize the span

4. Made the zaptel settings as I have shown in the first post in this series

5. Start zaptel service

6. Build and insert module

7. Run ztcfg

8. On the console, dial 1000

9. tail -f /var/log/messages should show message from hooksig

10. On the console, hangup

11. tail -f /var/log/messages should show message from hooksig

12. Since syslog buffers the message and does stuff like "Last message repeated X times" you might not see the second message immediately

#include
#include
#include "zaptel.h"

MODULE_LICENSE("GPL");

extern int gpltest;

struct hpvt {
int pos;
struct zt_span span;
struct zt_chan chan;
char variety[128];
}hello;

static int hello_spanInit();

static int hello_init(void)
{
printk(KERN_ALERT "Before: Hello, world %d \n",gpltest);
hello_spanInit();
printk(KERN_ALERT "After: Hello, world\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Before: Goodbye, cruel world\n");
zt_unregister(&hello.span);
printk(KERN_ALERT "After: Goodbye, cruel world\n");
}

static int wcfxo_open(struct zt_chan *c)
{

printk(KERN_ALERT "Open called\n");
return 0;
}

static int wcfxo_close(struct zt_chan *c)
{

printk(KERN_ALERT "Close called\n");
return 0;
}

static int wcfxo_hooksig(struct zt_chan *chan, zt_txsig_t txsig)
{

printk(KERN_ALERT "Hooksig called\n");
return 0;

}

static int wcfxo_watchdog(struct zt_span *span, int event)
{
printk("FXO: Restarting DMA\n");
return 0;
}


static int hello_spanInit()
{
struct hpvt *wc=&hello;

strcpy(hello.variety,"Thinvent");
hello.pos=0;
/* Zapata stuff */
sprintf(hello.span.name, "SARIN/%d", wc->pos);
snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Board %d", wc->variety, wc->pos + 1);
sprintf(wc->chan.name, "SARIN/%d/%d", wc->pos, 0);
snprintf(wc->span.location, sizeof(wc->span.location) - 1,"HERE!");
wc->span.manufacturer = "SARIN";
strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
wc->chan.sigcap = ZT_SIG_FXSKS | ZT_SIG_FXSLS | ZT_SIG_SF;
wc->chan.chanpos = 1;
wc->span.chans = &wc->chan;
wc->span.channels = 1;
wc->span.hooksig = wcfxo_hooksig;
// wc->span.irq = wc->dev->irq;
wc->span.open = wcfxo_open;
wc->span.close = wcfxo_close;
wc->span.flags = ZT_FLAG_RBS;
wc->span.deflaw = ZT_LAW_MULAW;
wc->span.watchdog = wcfxo_watchdog;
#ifdef ENABLE_TASKLETS
tasklet_init(&wc->wcfxo_tlet, wcfxo_tasklet, (unsigned long)wc);
#endif
init_waitqueue_head(&wc->span.maintq);

wc->span.pvt = wc;
wc->chan.pvt = wc;
if (zt_register(&wc->span, 0)) {
printk("Unable to register span with zaptel\n");
return -1;
}
return 0;

}

module_init(hello_init);
module_exit(hello_exit);

Make file

obj-m += tzap.o
EXTRA_CFLAGS += -I/root/zaptel/kernel

all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules

No comments: