Example #1
0
/*
 * Function:     wimaxcu_get_rf_status
 * Description:  Get WiMAX radio status
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_get_rf_status(WIMAX_API_DEVICE_ID_P p_device_id)
{
	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 1;
	}

	printf("Radio Status: ");
	switch (DeviceStatus) {
	case WIMAX_API_DEVICE_STATUS_UnInitialized:
		printf("Device is not ready\n");
		break;
	case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW:
		printf("HW and SW Radios are OFF\n");
		break;
	case WIMAX_API_DEVICE_STATUS_RF_OFF_HW:
		printf("HW radio is OFF\n");
		break;
	case WIMAX_API_DEVICE_STATUS_RF_OFF_SW:
		printf("SW radio is OFF\n");
		break;
	default:
		printf("HW and SW radios are ON\n");
	}
	return 0;
}
Example #2
0
/*
 * Function:     wimaxcu_restore_factory_settings
 * Description:  Reset to the factory default setting
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_restore_factory_settings(WIMAX_API_DEVICE_ID_P p_device_id)
{
	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 1;
	}

	if (DeviceStatus != WIMAX_API_DEVICE_STATUS_RF_OFF_SW) {
		printf("WARNING!! The radio must be turned off to reset to factory setting.\n");
		printf("          This operation will erase previously stored scanned results\n");
		printf("          and you will lose the ability to connect to the preferred NSP.\n");
		return 1;
	}
	
	wmxStatus = CmdResetToFactorySettings(p_device_id);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return 1;
	}

	printf("WiMAX system is set to factory settings.\n");
	return 0;
}
Example #3
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;
}
Example #4
0
/*
 * Function:     wimaxcu_get_stats
 * Description:  Get statistics data
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_get_stats(WIMAX_API_DEVICE_ID_P p_device_id)
{
	WIMAX_API_RET wmxStatus;
	WIMAX_API_CONNECTION_STAT Statistics;
	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 1;
	}

	if (DeviceStatus != WIMAX_API_DEVICE_STATUS_Data_Connected) {
		// Dispaly a proper message and exit
		switch (DeviceStatus) {
		case WIMAX_API_DEVICE_STATUS_UnInitialized:
			printf("ERROR: Device not Initialized\n");
			break;
		case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW:
			printf("WARNING: HW and SW Radio is turned OFF\n");
			break;
		case WIMAX_API_DEVICE_STATUS_RF_OFF_HW:
			printf("WARNING: HW Radio is turned OFF\n");
			break;
		case WIMAX_API_DEVICE_STATUS_RF_OFF_SW:
			printf("WARNING: SW Radio is turned OFF\n");
			break;
		case WIMAX_API_DEVICE_STATUS_Ready:
		case WIMAX_API_DEVICE_STATUS_Scanning:
		case WIMAX_API_DEVICE_STATUS_Connecting:
			printf("WARNING: Network is not Connected\n");
			break;
		default:
			printf("ERROR: Unknown Device Status\n");
		}
		return 1;
	}

	wmxStatus = GetStatistics(p_device_id, &Statistics);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return 1;
	}

	printf("Statistics:\n");
	printf("\tTotal RX Bytes   : %lld bytes\n", Statistics.totalRxByte);
	printf("\tTotal TX Bytes   : %lld bytes\n", Statistics.totalTxByte);
	printf("\tTotal RX Packets : %lld\n", Statistics.totalRxPackets);
	printf("\tTotal TX Packets : %lld\n", Statistics.totalTxPackets);

	return 0;
}
Example #5
0
/*
 * Get the device's status from the device
 *
 * Does NOT cache the result
 * Does NOT trigger a state change in NetworkManager
 *
 * Returns < 0 errno code on error, status code if ok.
 */
static WIMAX_API_DEVICE_STATUS iwmx_sdk_get_device_status(struct wmxsdk *wmxsdk)
{
	WIMAX_API_RET r;
	char errstr[512];
	UINT32 errstr_size = sizeof(errstr);

	WIMAX_API_DEVICE_STATUS dev_status;
	WIMAX_API_CONNECTION_PROGRESS_INFO pi;

	r = GetDeviceStatus(&wmxsdk->device_id, &dev_status, &pi);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot read device state: %d (%s)", r, errstr);
		dev_status = -EIO;
	}
	return dev_status;
}
Example #6
0
/*
 * Function:     wimaxcu_get_system_status
 * Description:  Get the WiMAX device status from the GetDeviceStatus API
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_get_system_status(WIMAX_API_DEVICE_ID_P p_device_id)
{
	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 1;
	}

	PrintDeviceStatus(DeviceStatus);
	return 0;
}
Example #7
0
int wimaxcu_stop_scan(WIMAX_API_DEVICE_ID_P p_device_id)
{
    WIMAX_API_RET wmxStatus = WIMAX_API_RET_SUCCESS;
    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_Scanning)
    {

        wmxStatus = CmdStopScan(p_device_id);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            printf("ERROR: Failed to stop scanning.\n");
            return 1;
        }

    }
    return 0;
}
Example #8
0
/*
 * Function:     wimaxcu_get_connect_status
 * Description:  Get the current connection status of WiMAX Device
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_get_connect_status(WIMAX_API_DEVICE_ID_P p_device_id)
{
	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 1;
	}

	PrintDeviceStatus(DeviceStatus);

	// if connected or idle, display connected NSP info
	if (DeviceStatus == WIMAX_API_DEVICE_STATUS_Data_Connected) {
		wimaxcu_get_conn_nsp(p_device_id);
		wimaxcu_get_conn_time(p_device_id);
	}

	return 0;
}
Example #9
0
/**************************************************************************
 *
 *  Function:  ubsec_ioctl
 *
 *************************************************************************/
static int 
ubsec_ioctl(struct inode *inode,struct file *filp,unsigned int cmd, unsigned long arg)
{

  long			Retval=0;

  int                   status = 0;
  int                   deadlockctr = 0;
  
  unsigned short        value;

  
  
  /* Simple round robin scheduling of device. We need to increment
     first since the keysetup command may block. */
  
 TheBeginning:

  deadlockctr = 0;
  do {

    /* For diagnostic related stuff do not try any available devices */
    /* Try the intended device or all devices as directed by the command */

    if (cmd >= UBSEC_DEVICEDUMP || cmd == UBSEC_SELFTEST || cmd == UBSEC_FAILDEVICE) {
      break;
    }

    if(++deadlockctr == (NumDevices * 2)) {  /* to be conservative... */
#ifdef DEBUG_FAILOVER
      PRINTK("dispatch found no more devices.\n");
#endif
      return 1; /* error: no more devices */
    }

    if ((++SelectedDevice) == NumDevices)
      SelectedDevice=0;

  } while(GetDeviceStatus(DeviceInfoList[SelectedDevice]));

#ifdef DEBUG_FAILOVER
  printk("\n");
  PRINTK("dsptch-pre: SltdDev=%d,DevStati=%d %d\n", 
	 SelectedDevice, DeviceInfoList[0].DeviceStatus, DeviceInfoList[1].DeviceStatus);
#endif


  switch(cmd) {
#ifdef BCM_OEM_1
  case BCM_OEM_1_IOCTL1:
	BCM_OEM1_IOCTL1_HANDLER();
	break;
  case BCM_OEM_1_IOCTL2:
	BCM_OEM1_IOCTL2_HANDLER();
	break;
#endif /* BCM_OEM_1 */

  case UBSEC_ENCRYPT_DECRYPT_FUNC:
    status = do_encrypt(DeviceInfoList[SelectedDevice].Context, 
			(void *)arg, DeviceInfoList[SelectedDevice].Features);
    break;

  case UBSEC_KEY_SETUP_FUNC:
    status = ubsec_keysetup(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_MATH_FUNC:
    status = ubsec_math(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_RNG_FUNC:
    if (DeviceInfoList[SelectedDevice].Features & UBSEC_EXTCHIPINFO_RNG)
      status = ubsec_rng(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    else
      status = UBSEC_STATUS_NO_DEVICE;
    break;
    
  case UBSEC_TLS_HMAC_FUNC:
    status = ubsec_tlsmac(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;
    
  case UBSEC_SSL_MAC_FUNC:
    status = ubsec_sslmac(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;
    
  case UBSEC_SSL_HASH_FUNC:
    status = ubsec_hash(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_SSL_DES_FUNC:
    status = ubsec_sslcipher(DeviceInfoList[SelectedDevice].Context, (void *)arg,
			     DeviceInfoList[SelectedDevice].Features);
    break;

  case UBSEC_SSL_ARC4_FUNC:
    if (DeviceInfoList[SelectedDevice].Features & UBSEC_EXTCHIPINFO_ARC4)
      status = ubsec_sslarc4(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    else
      status = UBSEC_STATUS_NO_DEVICE;
    break;

  case UBSEC_CHIPINFO_FUNC:
    status = obsolete_chipinfo(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_STATS_FUNC:
    {
      ubsec_stats_io_t IOInfo;
      int device_num;
      if (copy_from_user((void *) &IOInfo,(void *) arg, sizeof(ubsec_stats_io_t)))
        return -EFAULT; 
      device_num  = IOInfo.device_num;


	if ( (device_num >= NumDevices) || (device_num < 0) )
		return -1;

      ubsec_GetStatistics(DeviceInfoList[device_num].Context, &IOInfo.dev_stats);
      if (copy_to_user((void *) arg, (void *) &IOInfo, sizeof(ubsec_stats_io_t)))
        return -EFAULT;
    }
    break;
    
  case UBSEC_EXTCHIPINFO_FUNC:
    if (copy_from_user((void *)&ExtChipInfo, (void *)arg, sizeof(ubsec_chipinfo_io_t)))
      return -EFAULT; 
    if (ExtChipInfo.Status !=sizeof(ubsec_chipinfo_io_t)) {
      UserCopySize = sizeof(ubsec_chipinfo_io_t);
      if (UserCopySize > ExtChipInfo.Status)
	UserCopySize = ExtChipInfo.Status;
      ExtChipInfo.Status = UBSEC_STATUS_NO_DEVICE;
      if (copy_to_user((void *)arg, (void *)&ExtChipInfo, UserCopySize))
        return -EFAULT;
      return(-1);
    }
    else if ((ExtChipInfo.CardNum >= NumDevices) || (ExtChipInfo.CardNum < 0)) {
      ExtChipInfo.CardNum = NumDevices; 
      ExtChipInfo.Status = UBSEC_STATUS_INVALID_PARAMETER; 
    }
    else {
      status = ubsec_chipinfo(DeviceInfoList[ExtChipInfo.CardNum].Context, &ExtChipInfo); 
      ExtChipInfo.NumDevices = NumDevices; 
      ExtChipInfo.Features &= DeviceInfoList[ExtChipInfo.CardNum].Features;
      ExtChipInfo.Status = UBSEC_STATUS_SUCCESS; 
    }
    if (copy_to_user((void *)arg, (void *)&ExtChipInfo, sizeof(ubsec_chipinfo_io_t)))
      return -EFAULT; 
    if (ExtChipInfo.Status != UBSEC_STATUS_SUCCESS)
      return(-1);
    else
      return(0);
    break;
    
  case UBSEC_DEVICEDUMP:
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=DumpDeviceInfo((PInt)&PInt_Contents);
    if (Retval)
      return(-1); /* Error */
    break;

  case UBSEC_FAILDEVICE:
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=FailDevices((PInt)&PInt_Contents);
    if (Retval)
      return(-1); /* Error */
    break;

  case UBSEC_SELFTEST:
#ifdef BCM_OEM_1
	DISABLE_BCM_OEM1();
#endif /*BCM_OEM_1 */
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=TestDevices((PInt)&PInt_Contents);
#ifdef BCM_OEM_1
	ENABLE_BCM_OEM1();
#endif /*BCM_OEM_1 */
    if (Retval)
      return (Retval); /* Error */

  case UBSEC_GETVERSION:
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=GetHardwareVersion((PInt)&PInt_Contents); /* For the moment one card */
    Retval=Retval<<16;
    Retval+=Version;
    #ifdef LINUX_IA64
    return Retval;
    #else
    return(-Retval);
    #endif
    break;

  case UBSEC_GETNUMCARDS:
	if (copy_to_user((void *)arg,&NumDevices,sizeof(int)))
          return -EFAULT;
    return NumDevices;


  case  UBSEC_GET_FUNCTION_PTRS:
	{
	ubsec_Function_Ptrs_t fptrs;
	get_ubsec_Function_Ptrs(&fptrs);
      	if (copy_to_user((void *) arg, (void *) &fptrs, sizeof(ubsec_Function_Ptrs_t)))
          return -EFAULT;
	}
    break;

#ifdef DVT 
  case UBSEC_RESERVED:
    if (copy_from_user((void *)&DVTparams, (void *)arg, sizeof(DVT_Params_t)))
      return -EFAULT;
    if ((DVTparams.CardNum >= NumDevices) || (DVTparams.CardNum < 0)) {
      {PRINTK("Invalid CardNum (%d), must be 0",DVTparams.CardNum);}
      if (NumDevices == 1)
	printk("\n");
      else
	printk("-%d\n",NumDevices-1);
      return -1; 
    }
    switch (DVTparams.Command) {
    case UBSEC_DVT_PAGESIZE: /* Wrapper command */
      DVTparams.OutParameter = Page_Size;
      if (!DVTparams.InParameter) {
	DVTparams.OutParameter = Page_Size = PAGE_SIZE;
	DVTparams.Status = UBSEC_STATUS_SUCCESS;
	Retval = UBSEC_STATUS_SUCCESS;
      }      
      else if ((DVTparams.InParameter > PAGE_SIZE) ||
	       (DVTparams.InParameter < 2)) {
	DVTparams.Status = UBSEC_STATUS_INVALID_PARAMETER;
      }
      else {
	if (!power_of_2(DVTparams.InParameter))
	  DVTparams.InParameter = next_smaller_power_of_2(DVTparams.InParameter);
	DVTparams.OutParameter = Page_Size; 
	Page_Size = DVTparams.InParameter; 
	DVTparams.Status = UBSEC_STATUS_SUCCESS;
	Retval = UBSEC_STATUS_SUCCESS;
      }
      break;
    default:
      /* Pass all other commands down to the SRL */
      Retval=ubsec_dvt_handler((void *)DeviceInfoList[DVTparams.CardNum].Context,(void *)&DVTparams); 
    };
    if (copy_to_user((void *)arg, (void *)&DVTparams, sizeof(DVT_Params_t)))
      return -EFAULT;
    return(Retval);
    break;
#endif /* DVT */

  default:
    return -EINVAL;
  }
  
#ifdef DEBUG_FAILOVER
  PRINTK("dsptch-pst: SltdDev=%d,DevStati=%d %d\n", 
	 SelectedDevice, DeviceInfoList[0].DeviceStatus, DeviceInfoList[1].DeviceStatus);
  if((status == ETIMEDOUT) || (status == -ETIMEDOUT)) {
    PRINTK("dispatch.c: TIMED OUT SelectedDevice=%d, DeviceStatus=%d\n", 
	   SelectedDevice, DeviceInfoList[SelectedDevice].DeviceStatus);
  }
#endif

  switch(status) {
  case 0:
    break;

  case (ETIMEDOUT):
    status = -ETIMEDOUT;
  case (-ETIMEDOUT):
    DeviceInfoList[SelectedDevice].DeviceStatus = TestDevice(SelectedDevice);
    /*  goto TheBeginning; */
    return(status);
    break;
    
  default:
    /*  goto TheBeginning; */
    return(status);
    break;
  }
  
  return 0;
}
Example #10
0
int wimaxcu_find_network(WIMAX_API_DEVICE_ID_P p_device_id, int profileId,
                         WIMAX_API_NSP_INFO_P nspInfo)
{
    WIMAX_API_RET wmxStatus = WIMAX_API_RET_SUCCESS;
    UINT32 numProfileList = MAX_PROFILE;
    int i = 0, j = 0,ret = 0;
    int time_out = 0;
    UINT32 numOfNSPs = MAX_DEVICE;
    WIMAX_API_DEVICE_STATUS DeviceStatus;
    WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo;
    WIMAX_API_NSP_INFO_P pNspInfo =
        (WIMAX_API_NSP_INFO_P) malloc(MAX_LEN * sizeof(WIMAX_API_NSP_INFO));
    WIMAX_API_PROFILE_INFO_P profilelist = (WIMAX_API_PROFILE_INFO_P)
                                           malloc(sizeof(WIMAX_API_PROFILE_INFO) * MAX_PROFILE);
    memset(profilelist, 0, sizeof(WIMAX_API_PROFILE_INFO) * MAX_PROFILE);

    //1. Get the profile list and network list
    wmxStatus =
        GetSelectProfileList(p_device_id, profilelist, &numProfileList);
    if (wmxStatus != WIMAX_API_RET_SUCCESS) {
        printf("ERROR: Could not fetch the profile list- ");
        PrintWmxStatus(wmxStatus);
        return 0;
    }

    if (numProfileList == 0) {
        printf("WARNING: Profile list is empty \n");
        return 0;
    }

    for (i = 0; i < numProfileList; i++) {
        // check the match
        if (profileId == profilelist[i].profileID) {
//
            // zero the memory
            memset(pNspInfo, 0,
                   sizeof(WIMAX_API_NSP_INFO) * MAX_LEN);
            wmxStatus =
                GetNetworkList(p_device_id, pNspInfo, &numOfNSPs);
            if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                printf
                ("ERROR: Could not fetch network list - ");
                PrintWmxStatus(wmxStatus);
                free(pNspInfo);
                free(profilelist);
                return 0;
            }
            if(numOfNSPs == 0)
            {
                //numOfNSPs is 0 now - it should be set to MAX
                numOfNSPs=MAX_DEVICE;
                printf("Searching....\n");
                wmxStatus = SubscribeNetworkSearch(p_device_id, &ind_network_search_cb );
                if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                    PrintWmxStatus(wmxStatus);
                    return 2;
                }
                wmxStatus = CmdNetworkSearch(p_device_id);
                if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                    PrintWmxStatus(wmxStatus);
                    return 1;
                }

                printf("Scanning %2d%% Done ", g_searchProgress);
                fflush(stdout);
                do {
                    if (wmxcu_sem_timeout(&g_semConnectionUtility,5*1000) == 1 )
                    {
                        time_out++;
                        //if (pthread_mutex_trylock(&g_console_owner_mutex) == 0) {
                        printf("\r");
                        printf("Scanning %2d%% Done ", g_searchProgress);
                        // printf("Scanning %2d% Done [", g_searchProgress);

                        for(i = 0; i<=time_out; i++)
                        {
                            printf("=");
                        }
                        printf("-");
                        // 					for(i = 0; i<=SCAN_TIMEOUT_IN_10SEC_ITREATIONS - time_out; i++)
                        // 					{
                        // 						printf(" ");
                        // 					}
                        // 					printf("]");
                        fflush(stdout);
                        //	pthread_mutex_unlock(&g_console_owner_mutex);
                        //}
                        wmxStatus = GetDeviceStatus(p_device_id, &DeviceStatus, &ConnectionProgressInfo);
                        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                            PrintWmxStatus(wmxStatus);
                            return 2;
                        }

                        if (DeviceStatus == WIMAX_API_DEVICE_STATUS_Ready) {
                            if (g_noNetworksFound == 1)
                                printf("\nNo networks found.\n");
                            break;
                        }

                        if (time_out > SCAN_TIMEOUT_IN_10SEC_ITREATIONS) {
                            if (g_noNetworksFound == 1) {
                                printf("\nNo networks found.\n");
                            } else {
                                printf("\nScan Operation timeout.\n");
                                // As Scan operation timed out
                                ret = 1;
                            }
                            break;
                        }
                    } else {
                        break;
                    }
                } while (1);
                wmxStatus = GetNetworkList(p_device_id, pNspInfo, &numOfNSPs);
                if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                    printf("ERROR: Attempt to connect not successfull - ");
                    PrintWmxStatus(wmxStatus);
                    free(pNspInfo);
                    return 2;
                }

                wmxStatus = UnsubscribeNetworkSearch(p_device_id);
                if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                    PrintWmxStatus(wmxStatus);
                    return 2;
                }

            }


            if (numOfNSPs == 0) {
                printf("No available networks.\n");
                free(profilelist);
                free(pNspInfo);
                return 0;
            }
            for (j = 0; j < numOfNSPs; j++) {
                if ((pNspInfo[j].NSPid & 0xffffff) == profileId) {
                    // match with nspid, if there copy the nsp name and send it back
                    memcpy(nspInfo, &pNspInfo[j],
                           sizeof(WIMAX_API_NSP_INFO));
                    free(pNspInfo);
                    free(profilelist);
                    return 1;
                }
            }
        }
    }
    // return the proper status of this function

    free(profilelist);
    free(pNspInfo);
    // get the profile list and compare with nspid and return the result

    return 0;
}
Example #11
0
int wimaxcu_get_network_list_ex(WIMAX_API_DEVICE_ID_P p_device_id, CMD_ARGS scan_mode)
{
    int ret = 0;
    WIMAX_API_RET wmxStatus;
    int time_out = 0;
    WIMAX_API_CONNECTION_MODE connectMode;
    WIMAX_API_DEVICE_STATUS DeviceStatus;
    WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo;
    WIMAX_API_NSP_INFO_EX_P pNspInfo;

    UINT32 numOfNSPs = 20;
    int i = 0;

    // initialize the variable as No Networks found
    g_noNetworksFound = 1;
    g_searchProgress = 0;
    // get the device status
    wmxStatus =
        GetDeviceStatus(p_device_id, &DeviceStatus,
                        &ConnectionProgressInfo);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }

    switch (DeviceStatus) {
    case WIMAX_API_DEVICE_STATUS_UnInitialized: /**<  Device is uninitialized */
        printf("ERROR: Device not Initialized\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW:  /**<  Device RF Off(both H/W and S/W) */
        printf
        ("WARNING: HW and SW Radios are OFF.\nPlease turn ON the HW and SW Radios to perform a scan.\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_RF_OFF_HW:     /**<  Device RF Off(via H/W switch) */
        printf
        ("WARNING: HW Radio is OFF.\nPlease turn ON the HW Radio to perform a scan.\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_RF_OFF_SW:     /**<  Device RF Off(via S/W switch) */
        printf
        ("WARNING: SW Radio is OFF.\nPlease turn ON the SW Radio to perform a scan.\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_Ready:	     /**<  Device is ready */
    case WIMAX_API_DEVICE_STATUS_Scanning:	     /**<  Device is scanning */
        break;
    case WIMAX_API_DEVICE_STATUS_Connecting:    /**<  Connection in progress */
        printf("WARNING: Connection is in progress\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_Data_Connected:	/**<  Layer 2 connected */
        printf
        ("WARNING: Connection already established!\nPlease disconnect, before attempting to scan.\n");
        return 2;
    default:
        printf("ERROR: Device status Unknown.\n");
        return 2;
    }


    wmxStatus = SubscribeRfTaken(p_device_id, &ind_rf_taken_cb);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    wmxStatus = GetConnectionMode(p_device_id, &connectMode);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }

    if (connectMode == WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT
            && DeviceStatus == WIMAX_API_DEVICE_STATUS_Scanning) {
        printf
        ("WARNING: Scanning is in progress\nPlease wait for the current scan to complete.\n");
        return 2;
    }

    if (scan_mode == CMD_SCAN_ARG_PREFERRED) {

        wmxStatus =
            SubscribeNetworkSearchEx(p_device_id,
                                     &ind_network_search_cb_ex);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            return 2;
        }
        /* In Manual mode always scan do not read the cache as we don't know when cache was updated */
        if (connectMode !=
                WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT) {
            pNspInfo =
                (WIMAX_API_NSP_INFO_EX_P) malloc(MAX_LEN *
                                                 sizeof
                                                 (WIMAX_API_NSP_INFO_EX));
            memset(pNspInfo, 0,
                   sizeof(WIMAX_API_NSP_INFO_EX) * MAX_LEN);
            wmxStatus =
                GetNetworkListEx(p_device_id, pNspInfo, &numOfNSPs);
            if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                PrintWmxStatus(wmxStatus);
                /*
                   If the Device is already scanning, it won't allow one more AppSrv will reject it
                   with the Operation Falied error
                 */
                free(pNspInfo);
                return 1;
            }

            if (numOfNSPs != 0) {
                for (i = 0; i < numOfNSPs; i++) {
                    printf("\nNetwork found.\n");
                    PrintNSPInfoEx(&pNspInfo[i]);
                    if (wimaxcu_is_network_activated_ex
                            (p_device_id, &pNspInfo[i]))
                        printf("\tActivated\n");
                    else
                        printf("\tNot Activated\n");
                }
                return 0;
            }
        }

        wmxStatus = CmdNetworkSearch(p_device_id);

        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            if ((DeviceStatus == WIMAX_API_DEVICE_STATUS_Scanning)
                    && (wmxStatus == WIMAX_API_RET_FAILED)) {
                printf
                ("WARNING: Scanning is in progress\nPlease wait for the current scan to complete.\n");
            }
            return 1;
        }

        printf("Scanning %2d%% Done ", g_searchProgress);
        fflush(stdout);
        do {
            if (wmxcu_sem_timeout(&g_semConnectionUtility, 5 * 1000)
                    == 1) {
                time_out++;
                //if (pthread_mutex_trylock(&g_console_owner_mutex) == 0) {
                printf("\r");
                printf("Scanning %2d%% Done ",
                       g_searchProgress);
                // printf("Scanning %2d% Done [", g_searchProgress);

                for (i = 0; i <= time_out; i++) {
                    printf("=");
                }
                printf("-");
//                                      for(i = 0; i<=SCAN_TIMEOUT_IN_10SEC_ITREATIONS - time_out; i++)
//                                      {
//                                              printf(" ");
//                                      }
//                                      printf("]");
                fflush(stdout);
                //pthread_mutex_unlock(&g_console_owner_mutex);
                //}
                wmxStatus =
                    GetDeviceStatus(p_device_id, &DeviceStatus,
                                    &ConnectionProgressInfo);
                if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                    PrintWmxStatus(wmxStatus);
                    return 2;
                }

                if (DeviceStatus == WIMAX_API_DEVICE_STATUS_Ready) {
                    if (g_noNetworksFound == 1)
                        printf("\nNo networks found.\n");
                    break;
                }

                if (time_out > SCAN_TIMEOUT_IN_10SEC_ITREATIONS) {
                    if (g_noNetworksFound == 1) {
                        printf
                        ("\nNo networks found.\n");
                    } else {
                        printf
                        ("\nScan Operation timeout.\n");
                        // As Scan operation timed out
                        ret = 1;
                    }
                    break;
                }
            } else {
                break;
            }
        } while (1);

    } else if (scan_mode == CMD_SCAN_ARG_WIDE) {

        wmxStatus = SubscribeNetworkSearchWideScanEx(p_device_id,
                    &ind_network_search_wide_scan_cb_ex);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            return 2;
        }
        // Display the warning message:
        printf("WARNING: Wide scan may take upto 2 minutes... \n");
        wmxStatus = CmdNetworkSearchWideScan(p_device_id);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            /*
               If the Device is already scanning, it won't allow one more AppSrv will reject it
               with the Operation Falied wrror
             */
            if ((DeviceStatus == WIMAX_API_DEVICE_STATUS_Scanning)
                    && (wmxStatus == WIMAX_API_RET_FAILED)) {
                printf
                ("WARNING: Scanning is in progress\nPlease wait for the current scan to complete.\n ");

            }
            return 1;
        }

        if (wmxcu_sem_timeout(&g_semConnectionUtility, 120 * 1000) == 1)
            printf("No networks found.\n");
    }
    wmxStatus = UnsubscribeRfTaken(p_device_id);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    wmxStatus = UnsubscribeNetworkSearchEx(p_device_id);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    wmxStatus = UnsubscribeNetworkSearchWideScanEx(p_device_id);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    return ret;
}
Example #12
0
//------------------------------------------------------------------------------
/// Handles the given request if it is standard, otherwise STALLs it.
/// \param pDriver  Pointer to a USBDDriver instance.
/// \param pRequest  Pointer to a USBGenericRequest instance.
//------------------------------------------------------------------------------
void USBDDriver_RequestHandler(
    USBDDriver *pDriver,
    const USBGenericRequest *pRequest)
{
    unsigned char cfgnum;
    unsigned char infnum;
    unsigned char eptnum;
    unsigned char setting;
    unsigned char type;
    unsigned char indexDesc;
    unsigned int length;
    unsigned int address;

    TRACE_INFO_WP("Std ");

    // Check request code
    switch (USBGenericRequest_GetRequest(pRequest)) {

        case USBGenericRequest_GETDESCRIPTOR:
            TRACE_INFO_WP("gDesc ");

            // Send the requested descriptor
            type = USBGetDescriptorRequest_GetDescriptorType(pRequest);
            indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest);
            length = USBGenericRequest_GetLength(pRequest);
            GetDescriptor(pDriver, type, indexDesc, length);
            break;

        case USBGenericRequest_SETADDRESS:
            TRACE_INFO_WP("sAddr ");

            // Sends a zero-length packet and then set the device address
            address = USBSetAddressRequest_GetAddress(pRequest);
            USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address);
            break;

        case USBGenericRequest_SETCONFIGURATION:
            TRACE_INFO_WP("sCfg ");

            // Set the requested configuration
            cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest);
            SetConfiguration(pDriver, cfgnum);
            break;

        case USBGenericRequest_GETCONFIGURATION:
            TRACE_INFO_WP("gCfg ");

            // Send the current configuration number
            GetConfiguration(pDriver);
            break;

        case USBGenericRequest_GETSTATUS:
            TRACE_INFO_WP("gSta ");
    
            // Check who is the recipient
            switch (USBGenericRequest_GetRecipient(pRequest)) {
    
                case USBGenericRequest_DEVICE:
                    TRACE_INFO_WP("Dev ");
    
                    // Send the device status
                    GetDeviceStatus(pDriver);
                    break;
    
                case USBGenericRequest_ENDPOINT:
                    TRACE_INFO_WP("Ept ");
    
                    // Send the endpoint status
                    eptnum = USBGenericRequest_GetEndpointNumber(pRequest);
                    GetEndpointStatus(eptnum);
                    break;
    
                default:
                    TRACE_WARNING(
                              "USBDDriver_RequestHandler: Unknown recipient (%d)\n\r",
                              USBGenericRequest_GetRecipient(pRequest));
                    USBD_Stall(0);
            }
            break;

        case USBGenericRequest_CLEARFEATURE:
            TRACE_INFO_WP("cFeat ");

            // Check which is the requested feature
            switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {

                case USBFeatureRequest_ENDPOINTHALT:
                    TRACE_INFO_WP("Hlt ");

                    // Unhalt endpoint and send a zero-length packet
                    USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest));
                    USBD_Write(0, 0, 0, 0, 0);
                    break;

                case USBFeatureRequest_DEVICEREMOTEWAKEUP:
                    TRACE_INFO_WP("RmWU ");

                    // Disable remote wake-up and send a zero-length packet
                    pDriver->isRemoteWakeUpEnabled = 0;
                    USBD_Write(0, 0, 0, 0, 0);
                    break;

                default:
                    TRACE_WARNING(
                              "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
                              USBFeatureRequest_GetFeatureSelector(pRequest));
                    USBD_Stall(0);
            }
            break;

    case USBGenericRequest_SETFEATURE:
        TRACE_INFO_WP("sFeat ");

        // Check which is the selected feature
        switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {

            case USBFeatureRequest_DEVICEREMOTEWAKEUP:
                TRACE_INFO_WP("RmWU ");

                // Enable remote wake-up and send a ZLP
                pDriver->isRemoteWakeUpEnabled = 1;
                USBD_Write(0, 0, 0, 0, 0);
                break;

            case USBFeatureRequest_ENDPOINTHALT:
                TRACE_INFO_WP("Halt ");
                // Halt endpoint
                USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
                USBD_Write(0, 0, 0, 0, 0);
                break;

#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS)

            case USBFeatureRequest_TESTMODE:
                // 7.1.20 Test Mode Support
                if ((USBGenericRequest_GetType(pRequest) == USBGenericRequest_DEVICE)
                    && ((USBGenericRequest_GetIndex(pRequest) & 0x000F) == 0)) {

                    // Handle test request
                    USBDDriver_Test(USBFeatureRequest_GetTestSelector(pRequest));
                }
                else {

                    USBD_Stall(0);
                }
                break;
#endif
#if defined(CHIP_USB_OTGHS)
            case USBFeatureRequest_OTG_B_HNP_ENABLE:
                    TRACE_INFO_WP("OTG_B_HNP_ENABLE ");
                    otg_features_supported |= 1<<USBFeatureRequest_OTG_B_HNP_ENABLE;
                    USBD_Write(0, 0, 0, 0, 0);
                break;
            case USBFeatureRequest_OTG_A_HNP_SUPPORT:
                    TRACE_INFO_WP("OTG_A_HNP_SUPPORT ");
                    otg_features_supported |= 1<<USBFeatureRequest_OTG_A_HNP_SUPPORT;
                    USBD_Write(0, 0, 0, 0, 0);
                break;
            case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT:
                    TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT ");
                    otg_features_supported |= 1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT;
                    USBD_Write(0, 0, 0, 0, 0);
                break;
#endif
            default:
                TRACE_WARNING(
                          "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
                          USBFeatureRequest_GetFeatureSelector(pRequest));
                USBD_Stall(0);
        }
        break;

    case USBGenericRequest_SETINTERFACE:
        TRACE_INFO_WP("sInterface ");

        infnum = USBInterfaceRequest_GetInterface(pRequest);
        setting = USBInterfaceRequest_GetAlternateSetting(pRequest);
        SetInterface(pDriver, infnum, setting);
        break;

    case USBGenericRequest_GETINTERFACE:
        TRACE_INFO_WP("gInterface ");

        infnum = USBInterfaceRequest_GetInterface(pRequest);
        GetInterface(pDriver, infnum);
        break;

    default:
        TRACE_WARNING(
                  "USBDDriver_RequestHandler: Unknown request code (%d)\n\r",
                  USBGenericRequest_GetRequest(pRequest));
        USBD_Stall(0);
    }
}
Example #13
0
/*
 * Function:     SetUserConnectMode
 * Description:  Change the user connect mode
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_set_user_connect_mode(WIMAX_API_DEVICE_ID_P p_device_id,
		       char *connect_mode, char *scan_mode)
{
	int ret;
	WIMAX_API_RET wmxStatus;
	WIMAX_API_CONNECTION_MODE userConnectMode, currentConnectMode;
	WIMAX_API_DEVICE_STATUS DeviceStatus;
	WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo;

	wmxStatus = GetConnectionMode(p_device_id, &currentConnectMode);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return 1;
	}

	userConnectMode = currentConnectMode;
	ret =
	    ConvertCharToConnectionMode(connect_mode, scan_mode,
					&userConnectMode);
	if (ret == -1) {
		printf("Specified Scan/Connect mode(s) not recognized.\n");
		PrintUserConnectionMode(currentConnectMode);
		return 1;
	} else if (ret == -2) {
		printf("WARNING: Invalid connect and scan combination.\n");
		printf("Auto connection requires semi scan mode.\n");
		PrintUserConnectionMode(currentConnectMode);
		return 1;
	}

	if (userConnectMode == currentConnectMode) {
		printf("The specified connect mode is already in place.\n");
		PrintUserConnectionMode(currentConnectMode);
		return 1;
	}
	if (ret == 1) {
		wmxStatus =
		    GetDeviceStatus(p_device_id, &DeviceStatus,
				    &ConnectionProgressInfo);
		if (WIMAX_API_RET_SUCCESS != wmxStatus) {
			PrintWmxStatus(wmxStatus);
			return 2;
		}
	}

	if((userConnectMode == WIMAX_API_CONNECTION_SEMI_MANUAL_SCAN_AUTO_CONNECT)&&((DeviceStatus==WIMAX_API_DEVICE_STATUS_RF_OFF_SW)||(DeviceStatus==WIMAX_API_DEVICE_STATUS_RF_OFF_HW)||(DeviceStatus==WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW))){
		printf("Error:Please turn the Radio On\n");
		return 1;
	}

	wmxStatus = SetConnectionMode(p_device_id, userConnectMode);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		// PrintWmxStatus(wmxStatus);
		if (WIMAX_API_RET_FAILED == wmxStatus) {
			BOOL isEnable;
			wmxStatus =
			    GetConnectedAsCurrentPreferredCapabilityStatus
			    (p_device_id, &isEnable);
			if (wmxStatus == WIMAX_API_RET_SUCCESS) {
				if (isEnable == FALSE) {
					printf
					    ("Current Connected Network Preferred settings are disabled\n");
					printf
					    ("Hence could not set the connect mode to Auto \n");
					printf
					    ("Going back to the pprevious connect mode \n");
					wmxStatus =
					    SetConnectionMode(p_device_id,
							      currentConnectMode);
					if (WIMAX_API_RET_SUCCESS != wmxStatus) {
						PrintWmxStatus(wmxStatus);
					} else {
						PrintUserConnectionMode
						    (currentConnectMode);
					}
					return 1;
				} else {
					printf("Operation Failed \n");
					return 1;
				}
			}
		}
		PrintWmxStatus(wmxStatus);
		return 1;
	}
	// Unset the preferred NSP
	if (userConnectMode == WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT) {
		g_preferred_NSP_ID = 0;
		SetCurrentPreferredProfiles(p_device_id, &g_preferred_NSP_ID, 0);
	}
	PrintUserConnectionMode(userConnectMode);
	
	return 0;
}
Example #14
0
/**
 * Handles the given request if it is standard, otherwise STALLs it.
 * \param pDriver  Pointer to a USBDDriver instance.
 * \param pRequest  Pointer to a USBGenericRequest instance.
 */
void USBDDriver_RequestHandler(
    USBDDriver *pDriver,
    const USBGenericRequest *pRequest)
{
    uint8_t cfgnum;
    uint8_t infnum;
    uint8_t eptnum;
    uint8_t setting;
    uint8_t type;
    uint8_t indexDesc;
    uint32_t length;
    uint32_t address;

    TRACE_INFO_WP("Std ");

    /* Check request code */
    switch (USBGenericRequest_GetRequest(pRequest)) {

        case USBGenericRequest_GETDESCRIPTOR:
            TRACE_INFO_WP("gDesc ");

            /* Send the requested descriptor */
            type = USBGetDescriptorRequest_GetDescriptorType(pRequest);
            indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest);
            length = USBGenericRequest_GetLength(pRequest);
            GetDescriptor(pDriver, type, indexDesc, length);
            break;

        case USBGenericRequest_SETADDRESS:
            TRACE_INFO_WP("sAddr ");

            /* Sends a zero-length packet and then set the device address */
            address = USBSetAddressRequest_GetAddress(pRequest);
            USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address);
            break;

        case USBGenericRequest_SETCONFIGURATION:
            TRACE_INFO_WP("sCfg ");

            /* Set the requested configuration */
            cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest);
            SetConfiguration(pDriver, cfgnum);
            break;

        case USBGenericRequest_GETCONFIGURATION:
            TRACE_INFO_WP("gCfg ");

            /* Send the current configuration number */
            GetConfiguration(pDriver);
            break;

        case USBGenericRequest_GETSTATUS:
            TRACE_INFO_WP("gSta ");

            /* Check who is the recipient */
            switch (USBGenericRequest_GetRecipient(pRequest)) {

                case USBGenericRequest_DEVICE:
                    TRACE_INFO_WP("Dev ");

                    /* Send the device status */
                    GetDeviceStatus(pDriver);
                    break;

                case USBGenericRequest_ENDPOINT:
                    TRACE_INFO_WP("Ept ");

                    /* Send the endpoint status */
                    eptnum = USBGenericRequest_GetEndpointNumber(pRequest);
                    GetEndpointStatus(eptnum);
                    break;

                default:
                    TRACE_WARNING(
                              "USBDDriver_RequestHandler: Unknown recipient (%d)\n\r",
                              USBGenericRequest_GetRecipient(pRequest));
                    USBD_Stall(0);
            }
            break;

        case USBGenericRequest_CLEARFEATURE:
            TRACE_INFO_WP("cFeat ");

            /* Check which is the requested feature */
            switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {

                case USBFeatureRequest_ENDPOINTHALT:
                    TRACE_INFO_WP("Hlt ");

                    /* Unhalt endpoint and send a zero-length packet */
                    USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest));
                    USBD_Write(0, 0, 0, 0, 0);
                    break;

                case USBFeatureRequest_DEVICEREMOTEWAKEUP:
                    TRACE_INFO_WP("RmWU ");

                    /* Disable remote wake-up and send a zero-length packet */
                    pDriver->isRemoteWakeUpEnabled = 0;
                    USBD_Write(0, 0, 0, 0, 0);
                    break;

                default:
                    TRACE_WARNING(
                              "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
                              USBFeatureRequest_GetFeatureSelector(pRequest));
                    USBD_Stall(0);
            }
            break;

    case USBGenericRequest_SETFEATURE:
        TRACE_INFO_WP("sFeat ");

        /* Check which is the selected feature */
        switch (USBFeatureRequest_GetFeatureSelector(pRequest)) {

            case USBFeatureRequest_DEVICEREMOTEWAKEUP:
                TRACE_INFO_WP("RmWU ");

                /* Enable remote wake-up and send a ZLP */
                pDriver->isRemoteWakeUpEnabled = 1;
                USBD_Write(0, 0, 0, 0, 0);
                break;

            case USBFeatureRequest_ENDPOINTHALT:
                TRACE_INFO_WP("Halt ");
                /* Halt endpoint */
                USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
                USBD_Write(0, 0, 0, 0, 0);
                break;
            case USBFeatureRequest_OTG_B_HNP_ENABLE:
                    TRACE_INFO_WP("OTG_B_HNP_ENABLE ");
                    pDriver->otg_features_supported |=
                        1<<USBFeatureRequest_OTG_B_HNP_ENABLE;
                    USBD_Write(0, 0, 0, 0, 0);
                break;
            case USBFeatureRequest_OTG_A_HNP_SUPPORT:
                    TRACE_INFO_WP("OTG_A_HNP_SUPPORT ");
                    pDriver->otg_features_supported |=
                        1<<USBFeatureRequest_OTG_A_HNP_SUPPORT;
                    USBD_Write(0, 0, 0, 0, 0);
                break;
            case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT:
                    TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT ");
                    pDriver->otg_features_supported |=
                        1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT;
                    USBD_Write(0, 0, 0, 0, 0);
                break;

            default:
                TRACE_WARNING(
                          "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r",
                          USBFeatureRequest_GetFeatureSelector(pRequest));
                USBD_Stall(0);
        }
        break;

    case USBGenericRequest_SETINTERFACE:
        TRACE_INFO_WP("sInterface ");

        infnum = USBInterfaceRequest_GetInterface(pRequest);
        setting = USBInterfaceRequest_GetAlternateSetting(pRequest);
        SetInterface(pDriver, infnum, setting);
        break;

    case USBGenericRequest_GETINTERFACE:
        TRACE_INFO_WP("gInterface ");

        infnum = USBInterfaceRequest_GetInterface(pRequest);
        GetInterface(pDriver, infnum);
        break;

    default:
        TRACE_WARNING(
                  "USBDDriver_RequestHandler: Unknown request code (%d)\n\r",
                  USBGenericRequest_GetRequest(pRequest));
        USBD_Stall(0);
    }
}