bss.c (2421B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2024, Locus Robotics 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <ell/ell.h> 28 #include "ell/useful.h" 29 30 #include "client/dbus-proxy.h" 31 #include "client/display.h" 32 33 struct bss { 34 char *address; 35 }; 36 37 static const char *get_address(const void *data) 38 { 39 const struct bss *bss = data; 40 41 return bss->address; 42 } 43 44 static void update_address(void *data, struct l_dbus_message_iter *variant) 45 { 46 struct bss *bss = data; 47 const char *value; 48 49 l_free(bss->address); 50 51 if (!l_dbus_message_iter_get_variant(variant, "s", &value)) { 52 bss->address = NULL; 53 54 return; 55 } 56 57 bss->address = l_strdup(value); 58 } 59 60 static const struct proxy_interface_property bss_properties[] = { 61 { "Address", "s", update_address, get_address }, 62 { } 63 }; 64 65 static void *bss_create(void) 66 { 67 return l_new(struct bss, 1); 68 } 69 70 static void bss_destroy(void *data) 71 { 72 struct bss *bss = data; 73 74 l_free(bss->address); 75 l_free(bss); 76 } 77 78 static void bss_display_inline(const char *margin, const void *data) 79 { 80 const struct bss *bss = data; 81 82 display("%s%s\n", margin, bss->address); 83 } 84 85 static const struct proxy_interface_type_ops ops = { 86 .create = bss_create, 87 .destroy = bss_destroy, 88 .display = bss_display_inline, 89 }; 90 91 static struct proxy_interface_type bss_interface_type = { 92 .interface = IWD_BSS_INTERFACE, 93 .properties = bss_properties, 94 .ops = &ops, 95 }; 96 97 static int bss_interface_init(void) 98 { 99 proxy_interface_type_register(&bss_interface_type); 100 101 return 0; 102 } 103 104 static void bss_interface_exit(void) 105 { 106 proxy_interface_type_unregister(&bss_interface_type); 107 } 108 109 INTERFACE_TYPE(bss_interface_type, bss_interface_init, bss_interface_exit)