예제 #1
0
/*
 * Function:     wimaxcu_radio_on
 * Description:  Turn on the Radio
 * Return:       0 for success,
                 1 for failure, or
                 2 for non-command related error
 */
int wimaxcu_set_radio_on(WIMAX_API_DEVICE_ID_P p_device_id)
{
	int ret = 0;
	WIMAX_API_RET wmxStatus;
	WIMAX_API_DEVICE_STATUS DeviceStatus;
	WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo;

	wmxStatus =
	    GetDeviceStatus(p_device_id, &DeviceStatus,
			    &ConnectionProgressInfo);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return 2;
	}

	if (DeviceStatus == WIMAX_API_DEVICE_STATUS_RF_OFF_SW) {
		wmxStatus = CmdControlPowerManagement(p_device_id, WIMAX_API_RF_ON);
		if (WIMAX_API_RET_SUCCESS != wmxStatus) {
			PrintWmxStatus(wmxStatus);
            ret = 1;
		} else {
			// Wait 5 secs to get a confirmation of the updated(desired) device state before declaring success
			if (!wmxcu_sem_timeout(&g_semRfState, 5 * 1000)) {
				if ((g_devState ==
				     WIMAX_API_DEVICE_STATUS_Ready)
				    || (g_devState ==
					WIMAX_API_DEVICE_STATUS_Scanning)
				    || (g_devState ==
					WIMAX_API_DEVICE_STATUS_Connecting)
				    || (g_devState ==
					WIMAX_API_DEVICE_STATUS_Data_Connected))
				{
					printf("SW Radio is turned ON.\n");
					ret = 0;
				} else {
					printf
					    ("ERROR: Failed to turn SW Radio ON.\n");
					ret = 1;
				}
			} else {
				printf("ERROR: Failed to turn SW Radio ON.\n");
				ret = 1;
			}
		}
	} else if (DeviceStatus == WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW ||
		   DeviceStatus == WIMAX_API_DEVICE_STATUS_RF_OFF_HW) {
		printf
		    ("HW Radio is OFF.\nDisable HW Kill to turn ON the SW Radio.\n");
		ret = 1;
	} else if (DeviceStatus == WIMAX_API_DEVICE_STATUS_UnInitialized) {
		printf
		    ("ERROR: Turning the SW Radio ON unsuccessfull - Device is UnInitialized.\n");
		ret = 1;
	} else {
		printf("HW and SW Radios are ON.\n");
	}
	return ret;
}
예제 #2
0
/*
 * Turn the radio on or off
 *
 * First it checks that we are in the right state before doing
 * anything; there might be no need to do anything.
 *
 * Issue a command to the WiMAX API, wait for a callback confirming it
 * is done. Sometimes the callback is missed -- in that case, do force
 * a state change evaluation.
 *
 * Frustration note:
 *
 *      Geezoos efing Xist, they make difficult even the most simple
 *      of the operations
 *
 *      This thing is definitely a pain. If the radio is ON already
 *      and you switch it on again...well, there is no way to tell
 *      because you don't get a callback saying it basically
 *      suceeded. But on the other hand, if the thing was in a
 *      different state and action needs to be taken, you have to wait
 *      for a callback to confirm it's done. However, there is also an
 *      state change callback, which is almost the same, so now you
 *      have to handle things in two "unrelated" threads of execution.
 *
 *      How the shpx are you expected to tell the difference? Check
 *      status first? On timeout? Nice gap (eighteen wheeler size) for
 *      race conditions.
 */
int iwmx_sdk_rf_state_set(struct wmxsdk *wmxsdk, WIMAX_API_RF_STATE rf_state)
{
	int result;

	WIMAX_API_RET r;
	char errstr[512];
	UINT32 errstr_size = sizeof(errstr);
	WIMAX_API_DEVICE_STATUS dev_status;

	g_assert(rf_state == WIMAX_API_RF_ON || rf_state == WIMAX_API_RF_OFF);

	/* Guess what the current radio state is; if it is ON
	 * already, don't redo it. */
	dev_status = iwmx_sdk_get_device_status(wmxsdk);
	if ((int) dev_status < 0) {
		result = dev_status;
		goto error_get_status;
	}
	switch (dev_status) {
	case WIMAX_API_DEVICE_STATUS_UnInitialized:
		result = -EINVAL;
		goto error_cant_do;
	case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW:
	case WIMAX_API_DEVICE_STATUS_RF_OFF_HW:
		nm_log_err(LOGD_WIMAX, "wmxsdk: cannot turn on radio: hw switch is off");
		result = -EPERM;
		goto error_cant_do;
		break;
	case WIMAX_API_DEVICE_STATUS_RF_OFF_SW:
		if (rf_state == WIMAX_API_RF_OFF) {
			result = 0;
			nm_log_dbg(LOGD_WIMAX, "radio is already off");
			goto out_done;
		}
		break;
	case WIMAX_API_DEVICE_STATUS_Ready:
	case WIMAX_API_DEVICE_STATUS_Scanning:
	case WIMAX_API_DEVICE_STATUS_Connecting:
	case WIMAX_API_DEVICE_STATUS_Data_Connected:
		if (rf_state == WIMAX_API_RF_ON) {
			result = 0;
			nm_log_dbg(LOGD_WIMAX, "radio is already on");
			goto out_done;
		}
		break;
	default:
		g_assert(1);
	}
	/* Ok, flip the radio */
	r = CmdControlPowerManagement(&wmxsdk->device_id, rf_state);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot flip radio to %d: %d (%s) [device is in state %s]",
		           rf_state, r, errstr, iwmx_sdk_get_device_status_str(wmxsdk));
		result = -EIO;
	} else
		result = -EINPROGRESS;
out_done:
error_cant_do:
error_get_status:
	return result;
}