From: Alok Barsode <alok.bars...@linux.intel.com> --- src/connman.h | 11 ++++++----- src/rfkill.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/src/connman.h b/src/connman.h index 884463e..5e4db20 100644 --- a/src/connman.h +++ b/src/connman.h @@ -135,11 +135,6 @@ typedef void (*__connman_inet_rs_cb_t) (struct nd_router_advert *reply, int __connman_inet_ipv6_send_rs(int index, int timeout, __connman_inet_rs_cb_t callback, void *user_data); -#include <connman/rfkill.h> - -int __connman_rfkill_init(void); -void __connman_rfkill_cleanup(void); - #include <connman/resolver.h> int __connman_resolver_init(connman_bool_t dnsproxy); @@ -384,6 +379,12 @@ connman_bool_t __connman_device_get_reconnect(struct connman_device *device); const char *__connman_device_get_type(struct connman_device *device); +#include <connman/rfkill.h> + +int __connman_rfkill_init(void); +void __connman_rfkill_cleanup(void); +int __connman_rfkill_block(enum connman_service_type type, connman_bool_t block); + #include <connman/network.h> int __connman_network_init(void); diff --git a/src/rfkill.c b/src/rfkill.c index 3d214ef..17592da 100644 --- a/src/rfkill.c +++ b/src/rfkill.c @@ -41,6 +41,7 @@ enum rfkill_type { RFKILL_TYPE_WWAN, RFKILL_TYPE_GPS, RFKILL_TYPE_FM, + NUM_RFKILL_TYPES, }; enum rfkill_operation { @@ -74,6 +75,30 @@ static enum connman_service_type convert_type(uint8_t type) return CONNMAN_SERVICE_TYPE_UNKNOWN; } +static enum rfkill_type convert_service_type(enum connman_service_type type) +{ + switch (type) { + case CONNMAN_SERVICE_TYPE_WIFI: + return RFKILL_TYPE_WLAN; + case CONNMAN_SERVICE_TYPE_BLUETOOTH: + return RFKILL_TYPE_BLUETOOTH; + case CONNMAN_SERVICE_TYPE_WIMAX: + return RFKILL_TYPE_WIMAX; + case CONNMAN_SERVICE_TYPE_CELLULAR: + return RFKILL_TYPE_WWAN; + case CONNMAN_SERVICE_TYPE_GPS: + return RFKILL_TYPE_GPS; + case CONNMAN_SERVICE_TYPE_SYSTEM: + case CONNMAN_SERVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_VPN: + case CONNMAN_SERVICE_TYPE_GADGET: + case CONNMAN_SERVICE_TYPE_UNKNOWN: + return NUM_RFKILL_TYPES; + } + + return NUM_RFKILL_TYPES; +} + static GIOStatus rfkill_process(GIOChannel *chan) { unsigned char buf[32]; @@ -134,6 +159,37 @@ static gboolean rfkill_event(GIOChannel *chan, static GIOChannel *channel = NULL; +int __connman_rfkill_block(enum connman_service_type type, connman_bool_t block) +{ + uint8_t rfkill_type; + struct rfkill_event event; + ssize_t len; + int fd; + + DBG("type %d block %d", type, block); + + rfkill_type = convert_service_type(type); + if (rfkill_type == NUM_RFKILL_TYPES) + return -EINVAL; + + fd = open("/dev/rfkill", O_RDWR); + if (fd < 0) + return fd; + + memset(&event, 0, sizeof(event)); + event.op = RFKILL_OP_CHANGE_ALL; + event.type = rfkill_type; + event.soft = block; + + len = write(fd, &event, sizeof(event)); + if (len < 0) + connman_error("Failed to change RFKILL state"); + + close(fd); + + return 0; +} + int __connman_rfkill_init(void) { GIOFlags flags; -- 1.7.1 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman