Exemplo n.º 1
0
/******************************************************************************
 * 
 *    @name       VNIC_FEC_Init
 *    
 *    @brief      
 *                  
 *    @param      arg : handle to Identify the controller
 * 
 *    @return     None
 *   
 *****************************************************************************/
uint_32 VNIC_FEC_Init(CDC_CONFIG_STRUCT_PTR cdc_config_ptr)
{
    uint_32  error;
    boolean flag = FALSE;

    ENET_get_mac_address ((uint_32)ENET_DEVICE, nic_ip_addr, nic_mac_addr);

    error = ENET_initialize (ENET_DEVICE, nic_mac_addr, flag, &g_enet_handle);
    if(error != ENET_OK)
    {
        #if _DEBUG
            printf ("ENET_Initialization Failed\n");
        #endif  
        return ENETERR_INIT_FAILED; 
    }

    USB_mem_copy(nic_mac_addr, cdc_config_ptr->mac_address, MAC_ADDR_SIZE);
    cdc_config_ptr->ip_address =  nic_ip_addr;
    
    error = ENET_open(g_enet_handle, ENETPROT_IP, Ethernet_Callback, NULL);
    error |= ENET_open(g_enet_handle, ENETPROT_ARP, Ethernet_Callback, NULL);
    if(error != ENET_OK)
    {
        #if _DEBUG
            printf("ENET_open Failed.\n");
        #endif  
        return ENETERR_OPEN_PROT;
    }
    
    cdc_config_ptr->rndis_max_frame_size = ENET_FRAMESIZE_MAXDATA + ENET_FRAMESIZE_HEAD; 
    
    return error;
}
Exemplo n.º 2
0
/******************************************************************************
 * 
 *    @name       VNIC_FEC_Send
 *    
 *    @brief      
 *                  
 *    @param      arg : 
 *    @param      enet_hdr_ptr: 
 * 
 *    @return     None
 *   
 *****************************************************************************/     
uint_32 VNIC_FEC_Send(pointer arg, uint_8_ptr ethernet_frame_ptr, uint_32 payload_size)
{
    uint_16 protocol;
    uint_8_ptr nic_pcb = NULL;
    uint_32 error;
    PCB_FRAGMENT_PTR frag = NULL;
    UNUSED_ARGUMENT(arg)
    
    USB_mem_copy(ethernet_frame_ptr, 
        g_enet_hdr.DEST , MAC_ADDR_SIZE);
    USB_mem_copy(ethernet_frame_ptr + MAC_ADDR_SIZE, 
        g_enet_hdr.SOURCE, MAC_ADDR_SIZE);
    USB_mem_copy(ethernet_frame_ptr + 2 * MAC_ADDR_SIZE,
         g_enet_hdr.TYPE, 2);
        
    protocol = *((uint_16_ptr)(((ENET_HEADER_PTR)ethernet_frame_ptr)->TYPE)); 

    nic_pcb = _mem_alloc_system_zero(sizeof(PCB) + sizeof(PCB_FRAGMENT));
    if(nic_pcb == NULL) 
    {
      #if _DEBUG
        printf("Memalloc Failed in VNIC_FEC_Send\n");
      #endif    
      return ENETERR_ALLOC_PCB;
    } 

    frag = ((PCB_PTR)nic_pcb)->FRAG;
    ((PCB_PTR)nic_pcb)->FREE = (void(_CODE_PTR_)(PCB_PTR))VNIC_Send_PCB_Free;
    ((PCB_PTR)nic_pcb)->PRIVATE = NULL;
    frag[0].LENGTH = payload_size;

    frag[0].FRAGMENT = ethernet_frame_ptr;

    frag[1].LENGTH = 0;
    frag[1].FRAGMENT = NULL;
        
     error = ENET_send(g_enet_handle, (PCB_PTR)nic_pcb, protocol, 
        ((ENET_HEADER_PTR)ethernet_frame_ptr)->DEST, 0); //flag passed as Zero
    
    return error;
}
Exemplo n.º 3
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Init
 *
 * @brief The funtion initializes the Device and Controller layer 
 *
 * @param *cdc_config_ptr[IN]:  This structure contians configuration parameter
 *                              send by APP to configure CDC class.
 *
 * @return status       
 *         USB_OK           : When Successfull 
 *         Others           : Errors
 ******************************************************************************
 *
 *This function initializes the CDC Class layer and layers it is dependednt on 
 *
 *****************************************************************************/
uint_32 USB_Class_CDC_Init
(
  CDC_CONFIG_STRUCT_PTR cdc_config_ptr
)
{   
#if IMPLEMENT_QUEUING
    uint_8 index;
#endif

    uint_8 error;
    CDC_HANDLE cdc_handle;
    CDC_DEVICE_STRUCT_PTR devicePtr = NULL;
    USB_ENDPOINTS *usb_ep_data;
    
    if (NULL == (void *)cdc_config_ptr)
        return USBERR_ERROR;
    
    devicePtr = (CDC_DEVICE_STRUCT_PTR)USB_mem_alloc_zero(sizeof(CDC_DEVICE_STRUCT));
    if (NULL == devicePtr) 
    {
        #if _DEBUG
            printf("memalloc failed in USB_Class_CDC_Init\n");
        #endif  
        return USBERR_ALLOC;    
    }
    
    cdc_handle = USB_Cdc_Allocate_Handle();
    if (USBERR_DEVICE_BUSY == cdc_handle) 
    {
        USB_mem_free(devicePtr);
        devicePtr = NULL;
        return USBERR_INIT_FAILED;
    }

        /* initialize the Global Variable Structure */
    USB_mem_zero(devicePtr, sizeof(CDC_DEVICE_STRUCT));

    devicePtr->ep = cdc_config_ptr->ep;
    usb_ep_data = cdc_config_ptr->usb_ep_data;
    devicePtr->max_supported_interfaces = 
        cdc_config_ptr->max_supported_interfaces;
    #if RNDIS_SUPPORT
        USB_mem_copy(cdc_config_ptr->mac_address, devicePtr->mac_address, 
            sizeof(_enet_address));
        devicePtr->ip_address = cdc_config_ptr->ip_address;
        devicePtr->rndis_max_frame_size = cdc_config_ptr->rndis_max_frame_size;
    #endif
    /* Initialize the device layer*/
    error = _usb_device_init(USBCFG_DEFAULT_DEVICE_CONTROLLER, &devicePtr->controller_handle, (uint_8)(usb_ep_data->count+1));
    /* +1 is for Control Endpoint */ 
    if(error != USB_OK)
    {
      goto error1;  
    }
    
    cdc_config_ptr->desc_callback_ptr->handle = cdc_handle;
    
    /* Initialize the generic class functions */
    devicePtr->class_handle = USB_Class_Init(devicePtr->controller_handle,
    USB_Class_CDC_Event,USB_CDC_Other_Requests,(void *)devicePtr,
    cdc_config_ptr->desc_callback_ptr);

    /* Initialize the generic class functions */
    #if PSTN_SUBCLASS_NOTIF_SUPPORT
    /* Initialize the pstn subclass functions */
    error = USB_Pstn_Init(devicePtr,&cdc_config_ptr->param_callback);
    if(error != USB_OK)
    {
      goto error2;  
    }
    #endif
     
    devicePtr->usb_ep_data = usb_ep_data;
    #if IMPLEMENT_QUEUING
     for(index = 0; index < usb_ep_data->count; index++) 
     {            
        devicePtr->ep[index].endpoint = usb_ep_data->ep[index].ep_num;
        devicePtr->ep[index].type = usb_ep_data->ep[index].type;        
        devicePtr->ep[index].bin_consumer = 0x00;         
        devicePtr->ep[index].bin_producer = 0x00;        
      }
    #endif
        
    /* save the callback pointer */
    devicePtr->cdc_class_cb.callback = cdc_config_ptr->cdc_class_cb.callback;
    devicePtr->cdc_class_cb.arg = cdc_config_ptr->cdc_class_cb.arg;         
    /* save the callback pointer */
    devicePtr->vendor_req_callback.callback = 
    cdc_config_ptr->vendor_req_callback.callback;
    devicePtr->vendor_req_callback.arg = cdc_config_ptr->vendor_req_callback.arg; 
    /* save the callback pointer */
    devicePtr->param_callback.callback = cdc_config_ptr->param_callback.callback;
    devicePtr->param_callback.arg = cdc_config_ptr->param_callback.arg; 
    devicePtr->comm_feature_data_size =  cdc_config_ptr->comm_feature_data_size;  
    devicePtr->cic_send_endpoint = cdc_config_ptr->cic_send_endpoint;
    devicePtr->cic_recv_endpoint = USB_CONTROL_ENDPOINT;
    devicePtr->dic_send_endpoint = cdc_config_ptr->dic_send_endpoint;
    devicePtr->dic_recv_endpoint = cdc_config_ptr->dic_recv_endpoint; 
    devicePtr->dic_recv_pkt_size = cdc_config_ptr->dic_recv_pkt_size;
    devicePtr->dic_send_pkt_size = cdc_config_ptr->dic_send_pkt_size;
    devicePtr->cic_send_pkt_size = cdc_config_ptr->cic_send_pkt_size;
     
      
    devicePtr->cdc_handle = cdc_handle;
   
   cdc_device_array[cdc_handle] = devicePtr;
   
   return cdc_handle;
 error2:
  /* Implement Denit class and invoke here*/    
 error1: 
     USB_Cdc_Free_Handle(cdc_handle);
     USB_mem_free(devicePtr);
     devicePtr = NULL;    
    return error;    
}
Exemplo n.º 4
0
/**************************************************************************//*!
 *
 * @name  USB_Framework_Init
 *
 * @brief The funtion initializes the Class Module 
 *
 * @param handle :              handle to Identify the controller
 * @param class_callback:       event callback 
 * @param other_req_callback:   callback for vendor or usb framework class req    
 *
 * @return status       
 *         USB_OK           : When Successfull 
 *         Others           : Errors
 *
 *****************************************************************************/
USB_CLASS_FW_HANDLE USB_Framework_Init
(
    _usb_device_handle handle, /*[IN]*/
    USB_CLASS_CALLBACK class_callback,/*[IN]*/
    USB_REQ_FUNC other_req_callback,/*[IN]*/
    pointer callback_data,/*[IN]*/
    int_32 data,/*[IN]*/
    DESC_CALLBACK_FUNCTIONS_STRUCT_PTR  desc_callback_ptr /*[IN]*/
        
) 
{   
    USB_CLASS_FW_OBJECT_STRUCT_PTR usb_fw_ptr = NULL;
    USB_CLASS_FW_HANDLE fw_handle;
    uint_8 error=USB_OK;
    
    usb_fw_ptr = (USB_CLASS_FW_OBJECT_STRUCT_PTR)USB_mem_alloc_zero(
        sizeof(USB_CLASS_FW_OBJECT_STRUCT));
    if (NULL == usb_fw_ptr)
    {
        #ifdef _DEV_DEBUG
            printf("USB_Framework_Init: Memalloc failed\n");
        #endif  
        return USBERR_ALLOC;
    }

     if (USBERR_DEVICE_BUSY == USB_Class_Fw_Allocate_Handle(&fw_handle))
     {
        USB_mem_free((void *)usb_fw_ptr);
        usb_fw_ptr = NULL;
        return USBERR_ERROR;
     }
    /* save input parameters */
    
    usb_fw_ptr->class_handle = data;
    usb_fw_ptr->ext_req_to_host = NULL;

    /* reserve memory for setup token and data received */
    usb_fw_ptr->ext_req_to_host = (uint_8*)USB_mem_alloc_zero(MAX_EXPECTED_CONTROL_OUT_SIZE);
    if (NULL == usb_fw_ptr->ext_req_to_host)
    {
        #ifdef _DEV_DEBUG
            printf("ext_req_to_host malloc failed: USB_Framework_Init\n");
        #endif  
        return USBERR_ALLOC;
    }

    usb_fw_ptr->controller_handle = handle;
    usb_fw_ptr->other_req_callback.callback = other_req_callback;
    usb_fw_ptr->other_req_callback.arg = callback_data;
    usb_fw_ptr->class_callback.callback = class_callback;
    usb_fw_ptr->class_callback.arg = callback_data;
    USB_mem_copy( desc_callback_ptr,&usb_fw_ptr->desc,
    sizeof(DESC_CALLBACK_FUNCTIONS_STRUCT));
   
    /* Register CONTROL service */      
    error = _usb_device_register_service(handle, USB_SERVICE_EP0, 

#ifdef DELAYED_PROCESSING    
                                                 USB_Control_Service_Callback,
#else
                                                          USB_Control_Service,
#endif                                                          
     (pointer)usb_fw_ptr );
     
    usb_class_fw_object[fw_handle] = usb_fw_ptr;
    return fw_handle;     
}