1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** NetX Component */ 17 /** */ 18 /** Packet Pool Management (Packet) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define NX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "nx_api.h" 29 #include "nx_packet.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _nxe_packet_transmit_release PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Yuxin Zhou, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function checks for errors in the packet transmit release */ 45 /* function call. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* packet_ptr Pointer of packet to release */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* status Completion status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _nx_packet_transmit_release Actual packet transmit release*/ 58 /* function */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* Application Code */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 69 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _nxe_packet_transmit_release(NX_PACKET ** packet_ptr_ptr)73UINT _nxe_packet_transmit_release(NX_PACKET **packet_ptr_ptr) 74 { 75 76 UINT status; 77 NX_PACKET *packet_ptr; 78 79 80 /* Setup packet pointer. */ 81 packet_ptr = *packet_ptr_ptr; 82 83 /* Simple integrity check on the packet. */ 84 if ((packet_ptr == NX_NULL) || (packet_ptr -> nx_packet_pool_owner == NX_NULL) || 85 ((packet_ptr -> nx_packet_pool_owner) -> nx_packet_pool_id != NX_PACKET_POOL_ID)) 86 { 87 88 return(NX_PTR_ERROR); 89 } 90 91 /* Check for an invalid packet prepend pointer. */ 92 /*lint -e{946} suppress pointer subtraction, since it is necessary. */ 93 if (packet_ptr -> nx_packet_prepend_ptr < packet_ptr -> nx_packet_data_start) 94 { 95 return(NX_UNDERFLOW); 96 } 97 98 /* Check for an invalid packet append pointer. */ 99 /*lint -e{946} suppress pointer subtraction, since it is necessary. */ 100 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end) 101 { 102 return(NX_OVERFLOW); 103 } 104 105 /* Call actual packet transmit release function. */ 106 status = _nx_packet_transmit_release(packet_ptr); 107 108 /* Determine if the packet release was successful. */ 109 if (status == NX_SUCCESS) 110 { 111 112 /* Yes, now clear the application's packet pointer so it can't be accidentally 113 used again by the application. This is only done when error checking is 114 enabled. */ 115 *packet_ptr_ptr = NX_NULL; 116 } 117 118 /* Return completion status. */ 119 return(status); 120 } 121 122