1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 /**************************************************************************/ 12 /**************************************************************************/ 13 /** */ 14 /** USBX Component */ 15 /** */ 16 /** Device RNDIS Class */ 17 /** */ 18 /**************************************************************************/ 19 /**************************************************************************/ 20 21 #define UX_SOURCE_CODE 22 23 24 /* Include necessary system files. */ 25 26 #include "ux_api.h" 27 #include "ux_device_class_rndis.h" 28 #include "ux_device_stack.h" 29 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _ux_device_class_rndis_write PORTABLE C */ 36 /* 6.1.11 */ 37 /* AUTHOR */ 38 /* */ 39 /* Chaoqiong Xiao, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function writes a packet into a queue for later thread */ 44 /* processing. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* rndis Address of rndis class */ 49 /* instance */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* None */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _ux_device_mutex_on Take mutex */ 58 /* _ux_device_mutex_off Free mutex */ 59 /* _ux_device_event_flags_set Set event flags */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* ThreadX */ 64 /* */ 65 /* RELEASE HISTORY */ 66 /* */ 67 /* DATE NAME DESCRIPTION */ 68 /* */ 69 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 70 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 71 /* used UX prefix to refer to */ 72 /* TX symbols instead of using */ 73 /* them directly, */ 74 /* resulting in version 6.1 */ 75 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ 76 /* fixed standalone compile, */ 77 /* resulting in version 6.1.11 */ 78 /* */ 79 /**************************************************************************/ _ux_device_class_rndis_write(VOID * rndis_class,NX_PACKET * packet)80UINT _ux_device_class_rndis_write(VOID *rndis_class, NX_PACKET *packet) 81 { 82 #if defined(UX_DEVICE_STANDALONE) 83 UX_PARAMETER_NOT_USED(rndis_class); 84 UX_PARAMETER_NOT_USED(packet); 85 return(UX_FUNCTION_NOT_SUPPORTED); 86 #else 87 88 NX_PACKET *current_packet; 89 NX_PACKET *next_packet; 90 UX_SLAVE_CLASS_RNDIS *rndis; 91 92 /* Proper class casting. */ 93 rndis = (UX_SLAVE_CLASS_RNDIS *) rndis_class; 94 95 /* Protect this thread. */ 96 _ux_device_mutex_on(&rndis -> ux_slave_class_rndis_mutex); 97 98 /* Check the queue. See if there is something that is being sent. */ 99 if (rndis -> ux_slave_class_rndis_xmit_queue == UX_NULL) 100 101 /* Memorize this packet at the beginning of the queue. */ 102 rndis -> ux_slave_class_rndis_xmit_queue = packet; 103 104 else 105 106 { 107 108 /* We get here when there is something in the queue. */ 109 current_packet = rndis -> ux_slave_class_rndis_xmit_queue; 110 111 /* Get the next packet associated with the first packet. */ 112 next_packet = current_packet -> nx_packet_queue_next; 113 114 /* Parse the current chain for the end. */ 115 while (next_packet != NX_NULL) 116 { 117 /* Remember the current packet. */ 118 current_packet = next_packet; 119 120 /* See what the next packet in the chain is. */ 121 next_packet = current_packet -> nx_packet_queue_next; 122 } 123 124 /* Memorize the packet to be sent. */ 125 current_packet -> nx_packet_queue_next = packet; 126 127 } 128 129 /* Free Mutex resource. */ 130 _ux_device_mutex_off(&rndis -> ux_slave_class_rndis_mutex); 131 132 /* The packet to be sent is the last in the chain. */ 133 packet -> nx_packet_queue_next = NX_NULL; 134 135 /* Set an event to wake up the bulkin thread. */ 136 _ux_device_event_flags_set(&rndis -> ux_slave_class_rndis_event_flags_group, UX_DEVICE_CLASS_RNDIS_NEW_BULKIN_EVENT, UX_OR); 137 138 /* We are done here. */ 139 return(UX_SUCCESS); 140 #endif 141 } 142