Devi Sandeep Endluri V V | 893c122 | 2016-04-27 22:31:19 +0530 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are |
| 6 | met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above |
| 10 | copyright notice, this list of conditions and the following |
| 11 | disclaimer in the documentation and/or other materials provided |
| 12 | with the distribution. |
| 13 | * Neither the name of The Linux Foundation nor the names of its |
| 14 | contributors may be used to endorse or promote products derived |
| 15 | from this software without specific prior written permission. |
| 16 | |
| 17 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #define LOG_NDEBUG 0 |
| 32 | #define LOG_TAG "QtiConnectivityAdapter" |
| 33 | |
| 34 | #include <cutils/log.h> |
| 35 | #include <cutils/properties.h> |
| 36 | #include <dlfcn.h> |
| 37 | #include <sysutils/SocketClient.h> |
| 38 | #include <sysutils/SocketListener.h> |
| 39 | |
| 40 | #include "CommandListener.h" |
| 41 | #include "NetdCommand.h" |
| 42 | #include "QtiConnectivityAdapter.h" |
| 43 | #include "ResponseCode.h" |
| 44 | |
Devi Sandeep Endluri V V | 6139b84 | 2016-05-02 14:42:12 +0530 | [diff] [blame] | 45 | #ifdef USE_WRAPPER |
| 46 | #include "codeaurora/PropClientDispatch.h" |
| 47 | #endif |
| 48 | |
Devi Sandeep Endluri V V | 893c122 | 2016-04-27 22:31:19 +0530 | [diff] [blame] | 49 | void *_libConnectivityHandle = NULL; |
| 50 | void (*_initExtension) (SocketListener*) = NULL; |
| 51 | int (*_runQtiConnectivityCmd) (SocketClient*, int, char**) = NULL; |
| 52 | void (*_natStarted) (const char*, const char*) = NULL; |
| 53 | void (*_natStopped) (const char*, const char*) = NULL; |
| 54 | int (*_getV6TetherStats) (SocketClient*, const char*, const char*, std::string&) = NULL; |
| 55 | |
| 56 | void initLibrary() { |
| 57 | if (!_libConnectivityHandle) { |
| 58 | _libConnectivityHandle = dlopen("libconnctrl.so", RTLD_NOW); |
| 59 | if (_libConnectivityHandle) { |
| 60 | *(void **)&_initExtension = |
| 61 | dlsym(_libConnectivityHandle, "initExtension"); |
| 62 | *(void **)&_runQtiConnectivityCmd = |
| 63 | dlsym(_libConnectivityHandle, "runConnectivityCmd"); |
| 64 | *(void **)&_natStarted = |
| 65 | dlsym(_libConnectivityHandle, "natStarted"); |
| 66 | *(void **)&_natStopped = |
| 67 | dlsym(_libConnectivityHandle, "natStopped"); |
| 68 | *(void **)&_getV6TetherStats = |
| 69 | dlsym(_libConnectivityHandle, "getV6TetherStats"); |
| 70 | ALOGD("Successfully loaded %s", "libconnectivitycontroller"); |
| 71 | } else { |
| 72 | ALOGI("Failed to open libconnctrl, " |
| 73 | "some features may not be present."); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | NetdCommand* getQtiConnectivityCmd(CommandListener *broadcaster) { |
| 79 | initLibrary(); |
| 80 | if (_initExtension) _initExtension(broadcaster); |
| 81 | return (new QtiConnectivityCommand)->asNetdCommand(); |
| 82 | } |
| 83 | |
| 84 | void natStarted(const char* tetherIface, const char* upstreamIface) { |
| 85 | ALOGI("natStarted(tether=%s upstream=%s)", tetherIface, upstreamIface); |
| 86 | if (_natStarted) _natStarted(tetherIface, upstreamIface); |
| 87 | } |
| 88 | |
| 89 | void natStopped(const char* tetherIface, const char* upstreamIface) { |
| 90 | ALOGI("natStopped(tether=%s upstream=%s)", tetherIface, upstreamIface); |
| 91 | if (_natStopped) _natStopped(tetherIface, upstreamIface); |
| 92 | } |
| 93 | |
| 94 | int getV6TetherStats |
| 95 | ( |
| 96 | SocketClient *cli, |
| 97 | const char* tetherIface, |
| 98 | const char* upstreamIface, |
| 99 | std::string &extraProcessingInfo |
| 100 | ) { |
| 101 | ALOGI("getV6TetherStats(tether=%s upstream=%s)", tetherIface, upstreamIface); |
| 102 | if (_getV6TetherStats) return _getV6TetherStats(cli, |
| 103 | tetherIface, |
| 104 | upstreamIface, |
| 105 | extraProcessingInfo); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | NetdCommand *QtiConnectivityCommand::asNetdCommand() { |
| 110 | return static_cast<NetdCommand*>(this); |
| 111 | } |
| 112 | |
Devi Sandeep Endluri V V | 6139b84 | 2016-05-02 14:42:12 +0530 | [diff] [blame] | 113 | #ifdef USE_WRAPPER |
| 114 | int connAdapterGetHostByName(const pid_t pid, const uid_t uid, const gid_t gid, const char* name) { |
| 115 | if( __propClientDispatch.propGetHostByNameForNet ) { |
| 116 | return __propClientDispatch.propGetHostByNameForNet(pid, uid, gid, name); |
| 117 | } else { |
| 118 | return -1; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | int connAdapterGetHostByAddr(const pid_t pid, const uid_t uid, const gid_t gid, const void* addr) { |
| 123 | if( __propClientDispatch.propGetHostByAddrForNet ) { |
| 124 | return __propClientDispatch.propGetHostByAddrForNet(pid, uid, gid, addr); |
| 125 | } else { |
| 126 | return -1; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | int connAdapterGetAddrInfo( const pid_t pid, const uid_t uid, const gid_t gid, const char* hostname, const struct addrinfo* hints) { |
| 131 | if ( __propClientDispatch.propGetAddrInfoForNet ) { |
| 132 | return __propClientDispatch.propGetAddrInfoForNet(pid, uid, gid, hostname, hints); |
| 133 | } else { |
| 134 | return -1; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void connAdapterSendDnsReport( const int latencyMs ) { |
| 139 | if( __propClientDispatch.propSendDnsReport ) { |
| 140 | __propClientDispatch.propSendDnsReport(latencyMs); |
| 141 | } |
| 142 | } |
| 143 | #endif |
| 144 | |
Devi Sandeep Endluri V V | 893c122 | 2016-04-27 22:31:19 +0530 | [diff] [blame] | 145 | int QtiConnectivityCommand::runCommand |
| 146 | ( |
| 147 | SocketClient *cli, |
| 148 | int argc, |
| 149 | char **argv |
| 150 | ) { |
| 151 | if (_runQtiConnectivityCmd) { |
| 152 | return _runQtiConnectivityCmd(cli, argc, argv); |
| 153 | } else { |
| 154 | cli->sendMsg(ResponseCode::OperationFailed, "Extension not loaded", false); |
| 155 | } |
| 156 | return 0; |
| 157 | } |