CAResult_t CAIPStartNetworkMonitor() { OIC_LOG(DEBUG, TAG, "IN"); // Initialize Wifi service wifi_error_e ret = wifi_initialize(); if (WIFI_ERROR_NONE != ret) { OIC_LOG(ERROR, TAG, "wifi_initialize failed"); return CA_STATUS_FAILED; } // Set callback for receiving state changes ret = wifi_set_device_state_changed_cb(CAWIFIDeviceStateChangedCb, NULL); if (WIFI_ERROR_NONE != ret) { OIC_LOG(ERROR, TAG, "wifi_set_device_state_changed_cb failed"); return CA_STATUS_FAILED; } // Set callback for receiving connection state changes ret = wifi_set_connection_state_changed_cb(CAWIFIConnectionStateChangedCb, NULL); if (WIFI_ERROR_NONE != ret) { OIC_LOG(ERROR, TAG, "wifi_set_connection_state_changed_cb failed"); return CA_STATUS_FAILED; } OIC_LOG(DEBUG, TAG, "OUT"); return CA_STATUS_OK; }
static jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) { wifi_handle halHandle = getWifiHandle(env, cls); if (halHandle == NULL) { wifi_error res = wifi_initialize(&halHandle); if (res == WIFI_SUCCESS) { setStaticLongField(env, cls, WifiHandleVarName, (jlong)halHandle); ALOGD("Did set static halHandle = %p", halHandle); } env->GetJavaVM(&mVM); mCls = (jclass) env->NewGlobalRef(cls); ALOGD("halHandle = %p, mVM = %p, mCls = %p", halHandle, mVM, mCls); return res == WIFI_SUCCESS; } else { return true; } }
static int init() { ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); if (ioctl_sock < 0) { printMsg("Bad socket: %d\n", ioctl_sock); return errno; } else { printMsg("Good socket: %d\n", ioctl_sock); } int ret = linux_set_iface_flags(ioctl_sock, "wlan0", 1); if (ret < 0) { return ret; } wifi_error res = wifi_initialize(&halHandle); if (res < 0) { return res; } res = wifi_get_ifaces(halHandle, &numIfaceHandles, &ifaceHandles); if (res < 0) { return res; } char buf[EVENT_BUF_SIZE]; for (int i = 0; i < numIfaceHandles; i++) { if (wifi_get_iface_name(ifaceHandles[i], buf, sizeof(buf)) == WIFI_SUCCESS) { if (strcmp(buf, "wlan0") == 0) { printMsg("found interface %s\n", buf); wlan0Handle = ifaceHandles[i]; } else if (strcmp(buf, "p2p0") == 0) { printMsg("found interface %s\n", buf); p2p0Handle = ifaceHandles[i]; } } } return res; }
static void ESActivateWifi() { int error_code; error_code = wifi_initialize(); OIC_LOG_V(INFO,LOG_TAG,"#### WIFI INITIALIZED WITH STATUS :%d", error_code); error_code = wifi_activate(__wifi_activated_cb, NULL); OIC_LOG_V(INFO,LOG_TAG,"#### WIFI ACTIVATED WITH STATUS :%d", error_code); bool wifi_activated = false; wifi_is_activated(&wifi_activated); if (wifi_activated) { OIC_LOG(INFO,LOG_TAG,"#### Success to get Wi-Fi device state."); int scan_result = wifi_scan(__scan_request_cb, NULL); OIC_LOG_V(INFO,LOG_TAG,"#### Wifi scan result:%d", scan_result); } else { OIC_LOG(ERROR,LOG_TAG, "#### Fail to get Wi-Fi device state."); } }