コード例 #1
0
ファイル: wimaxcu_main.c プロジェクト: Brainiarc7/wimax-ns
/*
 * Function:     Initialize
 * Description:  Initialize the WiMAX CommonAPI
 */
WIMAX_API_RET wimaxcu_initialize(WIMAX_API_DEVICE_ID_P p_device_id)
{
	WIMAX_API_RET wmxStatus;
	WIMAX_API_HW_DEVICE_ID HwDeviceIdList[MAX_DEVICE];
	UINT32 numDevice = MAX_DEVICE;

	memset(HwDeviceIdList, 0, sizeof(WIMAX_API_HW_DEVICE_ID) * MAX_DEVICE);

	// open the Common API and initialize iwmax sdk, agents
	wmxStatus = WiMaxAPIOpen(p_device_id);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		return wmxStatus;
	}

	// get the list of the device before open the device
	wmxStatus = GetListDevice(p_device_id,
				  (WIMAX_API_HW_DEVICE_ID_P) HwDeviceIdList,
				  &numDevice);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		return wmxStatus;
	}

	p_device_id->deviceIndex = HwDeviceIdList[0].deviceIndex;

	// Open the device to get the permission
	wmxStatus = WiMaxDeviceOpen(p_device_id);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		return wmxStatus;
	}
	if (pthread_mutex_init(&g_console_owner_mutex, NULL) != 0) {
		printf("Internal Error!\n");
		return WIMAX_API_RET_FAILED;
	}

	if (sem_init(&g_semConnectionUtility, 0, 0) == -1) {
		printf("Internal Error!\n");
		return WIMAX_API_RET_FAILED;
	}

	if (sem_init(&g_semRfState, 0, 0) == -1) {
		printf("Internal Error!\n");
		return WIMAX_API_RET_FAILED;
	}

	if (sem_init(&g_semConnectCompleted, 0, 0) == -1) {
		printf("Internal Error!\n");
		return WIMAX_API_RET_FAILED;
	}

	wmxStatus =
	    SubscribeDeviceStatusChange(p_device_id, &ind_device_update_cb);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return WIMAX_API_RET_FAILED;
	}

	return WIMAX_API_RET_SUCCESS;
}
コード例 #2
0
ファイル: iwmxsdk.c プロジェクト: aelarabawy/NetworkManager
/*
 * Initialize the WiMAX API, register with it, setup callbacks
 *
 */
static int iwmx_sdk_setup(struct wmxsdk *wmxsdk)
{
	int result, status;

	WIMAX_API_RET r;

	char errstr[512];
	UINT32 errstr_size = sizeof(errstr);

	result = -ENFILE;

	/* device_id initialized by iwmx_sdk_dev_add */

	r = WiMaxDeviceOpen(&wmxsdk->device_id);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot open device: %d (%s)", r, errstr);
		goto error_wimaxdeviceopen;
	}

	/*
	 * We scan in auto mode (in the background)
	 *
	 * Otherwise is messy -- if we have NetworkManager triggering a scan
	 * when we call iwmx_nm_scan() -> iwmx_sdk_scan(), most of the
	 * times that causes a race condition when the UI asks for a
	 * scan right before displaying the network menu. As there is
	 * no way to cancel an ongoing scan before connecting, we are
	 * stuck. So we do auto bg and have iwmx_sdk_scan() just return
	 * the current network list.
	 */
	r = SetConnectionMode(&wmxsdk->device_id,
			      WIMAX_API_CONNECTION_AUTO_SCAN_MANUAL_CONNECT);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot set connectin mode to manual: %d (%s)", r, errstr);
		goto error_connection_mode;
	}

	r = SubscribeControlPowerManagement(&wmxsdk->device_id,
					    __iwmx_sdk_rf_state_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to radio change events: %u (%s)", r, errstr);
		result = -EIO;
		goto error_subscribe_rf_state;
	}

	r = SubscribeDeviceStatusChange(&wmxsdk->device_id,
					__iwmx_sdk_state_change_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to state chaneg events: %d (%s)", r, errstr);
		goto error_subscribe_state_change;
	}

	r = SubscribeNetworkSearchWideScanEx(&wmxsdk->device_id,
					     __iwmx_sdk_wide_scan_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to wide scan events: %d (%s)", r, errstr);
		goto error_subscribe_wide_scan;
	}
	r = SubscribeNetworkSearchEx(&wmxsdk->device_id, __iwmx_sdk_scan_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to scan events: %d (%s)", r, errstr);
		goto error_subscribe_scan;
	}

	r = SubscribeConnectToNetwork(&wmxsdk->device_id,
				      __iwmx_sdk_connect_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to connect events: %d (%s)", r, errstr);
		goto error_subscribe_connect;
	}

	r = SubscribeDisconnectToNetwork(&wmxsdk->device_id,
					 __iwmx_sdk_disconnect_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to disconnect events: %d (%s)", r, errstr);
		goto error_subscribe_disconnect;
	}

	r = SubscribeMediaStatusUpdate(&wmxsdk->device_id, __iwmx_sdk_media_status_update_cb);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to media status events: %d (%s)", r, errstr);
		goto error_subscribe_media_status;
	}

	status = iwmx_sdk_get_device_status(wmxsdk);
	if ((int) status < 0)
		status = WIMAX_API_DEVICE_STATUS_UnInitialized;

	g_mutex_lock(&wmxsdk->status_mutex);
	wmxsdk->status = status;
	g_mutex_unlock(&wmxsdk->status_mutex);

	_schedule_state_change(wmxsdk,
	                       status,
	                       WIMAX_API_DEVICE_STATUS_UnInitialized,
	                       WIMAX_API_STATUS_REASON_Normal,
	                       WIMAX_API_DEVICE_CONNECTION_PROGRESS_Ranging);

	return 0;

	UnsubscribeMediaStatusUpdate(&wmxsdk->device_id);
error_subscribe_media_status:
	UnsubscribeDisconnectToNetwork(&wmxsdk->device_id);
error_subscribe_disconnect:
	UnsubscribeConnectToNetwork(&wmxsdk->device_id);
error_subscribe_connect:
	UnsubscribeNetworkSearchEx(&wmxsdk->device_id);
error_subscribe_scan:
	UnsubscribeNetworkSearchWideScanEx(&wmxsdk->device_id);
error_subscribe_wide_scan:
	UnsubscribeDeviceStatusChange(&wmxsdk->device_id);
error_subscribe_state_change:
	UnsubscribeControlPowerManagement(&wmxsdk->device_id);
error_subscribe_rf_state:
error_connection_mode:
	WiMaxDeviceClose(&wmxsdk->device_id);
error_wimaxdeviceopen:
	return result;
}