mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added check for length of l2capoutbuf
This commit is contained in:
parent
ec53a2e4ba
commit
a70deaf5cc
1 changed files with 15 additions and 7 deletions
22
SPP.cpp
22
SPP.cpp
|
@ -674,31 +674,39 @@ uint8_t SPP::calcFcs(uint8_t *data) {
|
|||
|
||||
/* Serial commands */
|
||||
void SPP::print(const String &str) {
|
||||
uint8_t length = str.length();
|
||||
if(length > (sizeof(l2capoutbuf)-4))
|
||||
length = sizeof(l2capoutbuf)-4;
|
||||
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress;; // RFCOMM Address
|
||||
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
|
||||
l2capoutbuf[2] = str.length() << 1 | 1; // Length
|
||||
uint8_t i = 0;
|
||||
for(; i < str.length(); i++)
|
||||
l2capoutbuf[2] = length << 1 | 1; // Length
|
||||
uint8_t i = 0;
|
||||
for(; i < length; i++)
|
||||
l2capoutbuf[i+3] = str[i];
|
||||
l2capoutbuf[i+3] = calcFcs(l2capoutbuf);
|
||||
|
||||
RFCOMM_Command(l2capoutbuf,str.length()+4);
|
||||
RFCOMM_Command(l2capoutbuf,length+4);
|
||||
}
|
||||
void SPP::print(const char* data) {
|
||||
uint8_t length = strlen(data);
|
||||
if(length > (sizeof(l2capoutbuf)-4))
|
||||
length = sizeof(l2capoutbuf)-4;
|
||||
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress;; // RFCOMM Address
|
||||
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
|
||||
l2capoutbuf[2] = strlen(data) << 1 | 1; // Length
|
||||
l2capoutbuf[2] = length << 1 | 1; // Length
|
||||
uint8_t i = 0;
|
||||
for(; i < strlen(data); i++)
|
||||
for(; i < length; i++)
|
||||
l2capoutbuf[i+3] = data[i];
|
||||
l2capoutbuf[i+3] = calcFcs(l2capoutbuf);
|
||||
|
||||
RFCOMM_Command(l2capoutbuf,strlen(data)+4);
|
||||
RFCOMM_Command(l2capoutbuf,length+4);
|
||||
}
|
||||
void SPP::print(uint8_t data) {
|
||||
print(&data,1);
|
||||
}
|
||||
void SPP::print(uint8_t* array, uint8_t length) {
|
||||
if(length > (sizeof(l2capoutbuf)-4))
|
||||
length = sizeof(l2capoutbuf)-4;
|
||||
l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress;; // RFCOMM Address
|
||||
l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
|
||||
l2capoutbuf[2] = length << 1 | 1; // Length
|
||||
|
|
Loading…
Reference in a new issue