Fixed possible invalid program execution when in host mode if corrupt descriptor lengths are supplied by the attached device.
Minor code cleanups to add const and reformat where missing, as well as abstract out the internal device signature start address into a macro, so that it can be altered to suit particular devices within a single architecture if needed. Add missing documentation to the USB_Device_States_t enum.
This commit is contained in:
		
							parent
							
								
									78e58b6d1c
								
							
						
					
					
						commit
						049e930963
					
				
					 11 changed files with 67 additions and 28 deletions
				
			
		| 
						 | 
				
			
			@ -99,16 +99,22 @@
 | 
			
		|||
				 *  On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
 | 
			
		||||
				 *  number for the device.
 | 
			
		||||
				 */
 | 
			
		||||
				#define USE_INTERNAL_SERIAL           0xDC
 | 
			
		||||
				#define USE_INTERNAL_SERIAL            0xDC
 | 
			
		||||
 | 
			
		||||
				/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
 | 
			
		||||
				 *  model.
 | 
			
		||||
				 */
 | 
			
		||||
				#define INTERNAL_SERIAL_LENGTH_BITS   80
 | 
			
		||||
				#define INTERNAL_SERIAL_LENGTH_BITS    80
 | 
			
		||||
				
 | 
			
		||||
				/** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
 | 
			
		||||
				 *  model.
 | 
			
		||||
				 */
 | 
			
		||||
				#define INTERNAL_SERIAL_START_ADDRESS  0x0E
 | 
			
		||||
			#else
 | 
			
		||||
				#define USE_INTERNAL_SERIAL           NO_DESCRIPTOR
 | 
			
		||||
				#define USE_INTERNAL_SERIAL            NO_DESCRIPTOR
 | 
			
		||||
 | 
			
		||||
				#define INTERNAL_SERIAL_LENGTH_BITS   0
 | 
			
		||||
				#define INTERNAL_SERIAL_LENGTH_BITS    0
 | 
			
		||||
				#define INTERNAL_SERIAL_START_ADDRESS  0
 | 
			
		||||
			#endif			
 | 
			
		||||
			
 | 
			
		||||
		/* Function Prototypes: */
 | 
			
		||||
| 
						 | 
				
			
			@ -198,12 +204,13 @@
 | 
			
		|||
				return (UDADDR & (1 << ADDEN));
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
			static inline void USB_Device_GetSerialString(uint16_t* UnicodeString)
 | 
			
		||||
			#if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
 | 
			
		||||
			static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
 | 
			
		||||
			{
 | 
			
		||||
				uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
 | 
			
		||||
				GlobalInterruptDisable();
 | 
			
		||||
				
 | 
			
		||||
				uint8_t SigReadAddress = 0x0E;
 | 
			
		||||
				uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
 | 
			
		||||
 | 
			
		||||
				for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
 | 
			
		||||
				{
 | 
			
		||||
| 
						 | 
				
			
			@ -223,7 +230,8 @@
 | 
			
		|||
				
 | 
			
		||||
				SetGlobalInterruptMask(CurrentGlobalInt);
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
			#endif
 | 
			
		||||
 | 
			
		||||
	#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue