1 /* 2 * BlueZ - Bluetooth protocol stack for Linux 3 * 4 * Copyright (C) 2010 Instituto Nokia de Tecnologia - INdT 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #ifdef HAVE_CONFIG_H 22 #include <config.h> 23 #endif 24 25 #include <errno.h> 26 27 #include <bluetooth/bluetooth.h> 28 #include <bluetooth/hci.h> 29 #include <bluetooth/sdp.h> 30 #include <bluetooth/sdp_lib.h> 31 32 #include <gdbus.h> 33 34 #include "log.h" 35 #include "adapter.h" 36 #include "device.h" 37 38 #include "manager.h" 39 #include "server.h" 40 41 static DBusConnection *connection = NULL; 42 43 static int sap_server_probe(struct btd_adapter *adapter) 44 { 45 const char *path = adapter_get_path(adapter); 46 bdaddr_t src; 47 48 DBG("path %s", path); 49 50 adapter_get_address(adapter, &src); 51 52 return sap_server_register(path, &src); 53 } 54 55 static void sap_server_remove(struct btd_adapter *adapter) 56 { 57 const char *path = adapter_get_path(adapter); 58 59 DBG("path %s", path); 60 61 sap_server_unregister(path); 62 } 63 64 static struct btd_adapter_driver sap_server_driver = { 65 .name = "sap-server", 66 .probe = sap_server_probe, 67 .remove = sap_server_remove, 68 }; 69 70 int sap_manager_init(DBusConnection *conn) 71 { 72 connection = dbus_connection_ref(conn); 73 74 if (sap_server_init(connection) < 0) { 75 error("Can't init SAP server"); 76 dbus_connection_unref(conn); 77 return -1; 78 } 79 80 btd_register_adapter_driver(&sap_server_driver); 81 82 return 0; 83 } 84 85 void sap_manager_exit(void) 86 { 87 btd_unregister_adapter_driver(&sap_server_driver); 88 89 dbus_connection_unref(connection); 90 connection = NULL; 91 92 sap_server_exit(); 93 } 94