Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbd_core_webusb.c Source File

usbd_core_webusb.c

Go to the documentation of this file.
00001 /**
00002  * @file    usbd_core_webusb.c
00003  * @brief   WebUSB Device driver
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include <string.h>
00023 
00024 #include "rl_usb.h"
00025 #include "usb_for_lib.h"
00026 #include "info.h"
00027 
00028 /*
00029  *  USB Device Endpoint 0 Event Callback - WebUSB specific handling (Setup Request To Device)
00030  *    Parameters:      none
00031  *    Return Value:    TRUE - Setup vendor request ok, FALSE - Setup vendor request not supported
00032  */
00033 
00034 __weak BOOL USBD_EndPoint0_Setup_WebUSB_ReqToDevice(void)
00035 {
00036     U8  *pD;
00037     U32 len, n;
00038 
00039     BOOL success = (__FALSE);
00040     if (USBD_SetupPacket.bRequest == usbd_webusb_vendor_code) {         /* vendor code correct? */
00041         switch (USBD_SetupPacket.wIndex) {
00042             case WEBUSB_REQUEST_GET_URL:
00043                 pD = (U8 *)USBD_WebUSBURLDescriptor;
00044                 if (USBD_SetupPacket.wValueL == 0) {
00045                     success = (__FALSE);
00046                     break;
00047                 }
00048 
00049                 for (n = 0; n + 1 < USBD_SetupPacket.wValueL; n++) {
00050                     if (((WEBUSB_URL_DESCRIPTOR *)pD)->bLength != 0) {
00051                         pD += ((WEBUSB_URL_DESCRIPTOR *)pD)->bLength;
00052                     }
00053                 }
00054 
00055                 if (((WEBUSB_URL_DESCRIPTOR *)pD)->bLength == 0) {
00056                     success = (__FALSE);
00057                     break;
00058                 }
00059                 strcat(((WEBUSB_URL_DESCRIPTOR *)pD)->URL, info_get_board_id());
00060                 USBD_EP0Data.pData = pD;
00061                 len = ((WEBUSB_URL_DESCRIPTOR *)pD)->bLength;
00062 
00063                 success = (__TRUE);
00064                 break;
00065 
00066             default:
00067                 break;
00068         }
00069     }
00070 
00071     if (success) {
00072         if (len < USBD_SetupPacket.wLength) {
00073             USBD_EP0Data.Count = len;
00074             if (!(len & (usbd_max_packet0 - 1))) {
00075                 USBD_ZLP = 1;
00076             }
00077         } else {
00078             USBD_EP0Data.Count = USBD_SetupPacket.wLength;
00079         }
00080 
00081         USBD_DataInStage();
00082     }
00083 
00084     return success;
00085 }