@@ -134,21 +134,21 @@ void hdlcEncodeAndSendFrame(const uint8_t *data, const uint8_t len)
134134 // Calculate FCS of message
135135 uint16_t fcs = crc16 (data , len );
136136 // Append
137- uint8_t frame [len + 2 ];
137+ uint8_t frame [HDLC_MAX_FRAME_SIZE_BYTES ];
138138 memcpy (& frame , data , len );
139139 frame [len ] = low (fcs );
140140 frame [len + 1 ] = high (fcs );
141141 // Trace
142142 #ifdef TRACE_HDLC
143- uint8_t hexStrBuf [( len + 2 ) * 4 ];
143+ uint8_t hexStrBuf [HDLC_MAX_FRAME_SIZE_BYTES * 4 ];
144144 HexArrayToStr ((char * )hexStrBuf , frame , len + 2 );
145145 log_trace ("Encoded HDLC: %s" , hexStrBuf );
146146 #endif
147147 // See if we need to escape anything
148148 uint8_t escapes = HDLCGetEscapesReq (frame , len + 2 );
149149 if (escapes )
150150 {
151- uint8_t escFrame [len + 2 + escapes ];
151+ uint8_t escFrame [HDLC_MAX_FRAME_SIZE_BYTES ];
152152 if (HDLCEscape (escFrame , frame , len + 2 ) != escapes )
153153 {
154154 log_error ("Didn't escape the bytes we expected!" );
@@ -212,7 +212,7 @@ void HDLCSendRR()
212212void HDLCSendUI (uint8_t * msgData , uint8_t len )
213213{
214214 // We need 2 extra bytes for address and control
215- uint8_t data [len + 2 ];
215+ uint8_t data [HDLC_MAX_FRAME_SIZE_BYTES ];
216216 data [0 ] = peerAddress ;
217217 data [1 ] = HDLC_CTRL_UI ;
218218 memcpy (& data [2 ], msgData , len );
@@ -355,7 +355,7 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
355355{
356356 // Debug print hex buffer
357357 #ifdef TRACE_HDLC
358- uint8_t hexStrBuf [rawLen * 4 ];
358+ uint8_t hexStrBuf [HDLC_MAX_FRAME_SIZE_BYTES * 4 ];
359359 #endif
360360
361361 // Incremenet total frames processed
@@ -366,7 +366,7 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
366366 log_trace ("Processing %d-byte HDLC message:%s" , rawLen , hexStrBuf );
367367 #endif
368368 // Escape
369- uint8_t msg [rawLen ];
369+ uint8_t msg [HDLC_MAX_FRAME_SIZE_BYTES ];
370370 uint8_t len = rawLen - HDLCUnescape (msg , rawMsg , rawLen );
371371 #ifdef TRACE_HDLC
372372 if (len != rawLen )
@@ -380,11 +380,11 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
380380 uint8_t msg_ctrl = msg [1 ];
381381 // Data is bytes 2 to len-2 so buffer size is 4 less
382382 uint8_t data_len = len - 4 ;
383- uint8_t msg_data [data_len ];
383+ /* uint8_t msg_data[HDLC_MAX_FRAME_SIZE_BYTES ];
384384 memset(msg_data, 0, data_len);
385- memcpy (msg_data , & msg [2 ], (data_len ) * sizeof (uint8_t ));
385+ memcpy(msg_data, &msg[2], (data_len) * sizeof(uint8_t));*/
386386 #ifdef TRACE_HDLC
387- printHexArray ((char * )hexStrBuf , msg_data , data_len );
387+ printHexArray ((char * )hexStrBuf , msg + 2U , data_len );
388388 log_trace ("Msg data:%s" , hexStrBuf );
389389 #endif
390390 // Calculate expected FCS by getting the entire message minus the FCS
@@ -433,7 +433,7 @@ uint8_t HDLCParseMsg(uint8_t* rawMsg, uint8_t rawLen)
433433 log_info ("Got UI frame (len: %d)" , data_len );
434434 hdlcLastRx = HAL_GetTick ();
435435 // Write frame to VCP
436- VCPWriteP25Frame (msg_data , data_len );
436+ VCPWriteP25Frame (msg + 2U , data_len );
437437 break ;
438438 default :
439439 log_warn ("Unhandled HDLC control type %02X" , msg_ctrl );
0 commit comments