[ifxmips]
[openwrt/svn-archive/archive.git] / package / libtapi / src / tapi-device.c
1 #include <stdio.h>
2
3 #include "tapi-device.h"
4 #include "tapi-ioctl.h"
5
6 int tapi_device_open(unsigned int id, struct tapi_device *dev)
7 {
8 char path[100];
9
10 snprintf(path, sizeof(path), "/dev/tapi%dC", id);
11 dev->control_fd = open(path, 0);
12 if (dev->control_fd < 0)
13 return -1;
14
15 snprintf(dev->stream_path, 100, "/dev/tapi%dS", id);
16
17 dev->id = id;
18 dev->num_ports = 2;
19
20 return 0;
21 }
22
23 int tapi_link_alloc(struct tapi_device *dev, unsigned int ep1, unsigned int ep2)
24 {
25 return ioctl(dev->control_fd, TAPI_CONTROL_IOCTL_LINK_ALLOC, (ep1 << 16) | ep2);
26 }
27
28 int tapi_link_free(struct tapi_device *dev, unsigned int link)
29 {
30 return ioctl(dev->control_fd, TAPI_CONTROL_IOCTL_LINK_FREE, link);
31 }
32
33 int tapi_link_enable(struct tapi_device *dev, unsigned int link)
34 {
35 return ioctl(dev->control_fd, TAPI_CONTROL_IOCTL_LINK_ENABLE, link);
36 }
37
38 int tapi_link_disable(struct tapi_device *dev, unsigned int link)
39 {
40 return ioctl(dev->control_fd, TAPI_CONTROL_IOCTL_LINK_DISABLE, link);
41 }
42
43 int tapi_sync(struct tapi_device *dev)
44 {
45 return ioctl(dev->control_fd, TAPI_CONTROL_IOCTL_SYNC, 0);
46 }