3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
#include <sys/ioctl.h>
33
#include <sys/types.h>
35
#include <linux/sockios.h>
37
#include <bluetooth/bluetooth.h>
38
#include <bluetooth/l2cap.h>
39
#include <bluetooth/bnep.h>
45
static int bridge_socket = -1;
46
static const char *gn_bridge = NULL;
47
static const char *nap_bridge = NULL;
49
int bridge_init(const char *gn_iface, const char *nap_iface)
54
if (stat("/sys/module/bridge", &st) < 0)
57
bridge_socket = socket(AF_INET, SOCK_STREAM, 0);
58
if (bridge_socket < 0) {
59
error("Failed to open bridge socket: %s (%d)",
60
strerror(errno), errno);
65
nap_bridge = nap_iface;
70
void bridge_cleanup(void)
77
int bridge_create(int id)
80
const char *name = bridge_get_name(id);
82
err = ioctl(bridge_socket, SIOCBRADDBR, name);
86
info("bridge %s created", name);
91
int bridge_remove(int id)
94
const char *name = bridge_get_name(id);
96
err = bnep_if_down(name);
100
err = ioctl(bridge_socket, SIOCBRDELBR, name);
104
info("bridge %s removed", name);
109
int bridge_add_interface(int id, const char *dev)
113
int ifindex = if_nametoindex(dev);
114
const char *name = bridge_get_name(id);
122
memset(&ifr, 0, sizeof(ifr));
123
strncpy(ifr.ifr_name, name, IFNAMSIZ - 1);
124
ifr.ifr_ifindex = ifindex;
126
err = ioctl(bridge_socket, SIOCBRADDIF, &ifr);
130
info("bridge %s: interface %s added", name, dev);
132
err = bnep_if_up(name, id);
139
const char *bridge_get_name(int id)
141
if (id == BNEP_SVC_GN)
144
if (id == BNEP_SVC_NAP)