Skip to content

Commit

Permalink
TESTING
Browse files Browse the repository at this point in the history
  • Loading branch information
jprestwo committed Oct 2, 2023
1 parent 6c2f91a commit 72463c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/ckernelwifi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ int CKernelWifi::process_messages(struct nl_msg *msg)
}

int value=_SendSignal(&power, (char*)nlh, msg_len);
if( value == SOCKET_ERROR )
if( value == SOCKET_ERROR ) {
printf("Error sending to server\n");
manage_server_crash();
}

// Send also on the others interfaces on the same VM :
// ------------------->
Expand Down Expand Up @@ -449,8 +451,10 @@ void CKernelWifi::recv_from_server(){
return ;

TPower power;
if( _RecvSignal(&power, &dropped, &Buffer) == SOCKET_ERROR )
if( _RecvSignal(&power, &dropped, &Buffer) == SOCKET_ERROR ) {
printf("Error receiving from server\n");
manage_server_crash();
}

int signal = power ;

Expand Down Expand Up @@ -539,6 +543,7 @@ void CKernelWifi::recv_from_server(){
if (!dropped)
flags |= HWSIM_TX_STAT_ACK;

#if 0
struct nl_msg *tx_info = build_tx_info(&framesrc, flags,
(int)signal,
tx_rates,
Expand All @@ -549,8 +554,11 @@ void CKernelWifi::recv_from_server(){
int value=_SendSignal(&power, (char*)hdr, hdr->nlmsg_len);

nlmsg_free(tx_info);
if( value == SOCKET_ERROR )
if( value == SOCKET_ERROR ) {
printf("Error sending tx info to server\n");
manage_server_crash();
}
#endif

if (dropped)
return;
Expand Down Expand Up @@ -926,6 +934,7 @@ bool CKernelWifi::is_connected_to_server(){

void CKernelWifi::manage_server_crash(){

printf("MANAGE SERVER CRASH");
connected_to_server(false) ;

}
Expand Down
4 changes: 3 additions & 1 deletion src/csocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ ssize_t CSocket::SendBigData(TDescriptor descriptor, const char* data, TMinimalS
ssize_t CSocket::Read(TDescriptor descriptor, char* data, ssize_t sizeOfData)
{
ssize_t ret = recv(descriptor , data, sizeOfData, 0);
if ( ret <= 0 )
if ( ret <= 0 ) {
printf("Recv failed with %ld\n", errno);
return SOCKET_ERROR ;
}

return ret;
}
Expand Down
18 changes: 13 additions & 5 deletions src/cwifi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const double ConstanteC=92.45;
const TFrequency DEFAULT_FREQUENCY=2412; // Hz

const int MTU=1640; // Maximum Transmission Unit : 1640 is an experimental value
const int MTU=4096; // Maximum Transmission Unit : 1640 is an experimental value

TFrequency CWifi::GetFrequency(struct nlmsghdr* nlh)
{
Expand Down Expand Up @@ -83,24 +83,32 @@ ssize_t CWifi::RecvSignalWithSocket(CSocket* socket, TDescriptor descriptor, TPo

// read the power
valread = socket->Read(descriptor, (char*)power, sizeof(TPower));
if ( valread <= 0 )
if ( valread <= 0 ) {
printf("cannot read power %d\n", valread);
return valread;
}

// read dropped
valread = socket->Read(descriptor, (char*)dropped, sizeof(uint8_t));
if ( valread <= 0 )
if ( valread <= 0 ) {
printf("cannot read dropped %d\n", valread);
return valread;
}

// read the signal
// "nlmsg_len" (type "uint32_t") is the first attribut of the "struct nlmsghdr" in "libnl3/netlink/netlink-kernel.h"
ssize_t sizeRead = socket->ReadEqualSize(descriptor, buffer, 0, sizeof(struct nlmsghdr));
if( sizeRead == SOCKET_ERROR )
if( sizeRead == SOCKET_ERROR ) {
printf("Cannot read nlmsg_len\n");
return SOCKET_ERROR;
}

int sizeTotal=((struct nlmsghdr *)(buffer->GetBuffer()))->nlmsg_len;

if( sizeTotal > MTU ) // to avoid that a error packet overfulls the memory
if( sizeTotal > MTU ) { // to avoid that a error packet overfulls the memory
printf("Size greater than MTU %d\n", sizeTotal);
return SOCKET_ERROR;
}

return socket->ReadEqualSize(descriptor, buffer, sizeRead, sizeTotal);
}

0 comments on commit 72463c2

Please sign in to comment.