Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All is in C Code Programming. C Language. The main purpose is to - Add a CRC to the packet so that the packet itself

All is in C Code Programming. C Language.

The main purpose is to

- Add a CRC to the packet so that the packet itself carries a signature that is valid

and the receiving end can verify the signature.

- I have the code (with the missing CALL to inject the CRC into the Packet and READ the CRC and

validate the data)

- I need help because I do not know how to write this portion of the code to

Can you please insert the code into the raw code so I can copy into my Visual Studio and Test the code

***(1) create a CALL to inject the CRC into the Packet***

image text in transcribed

***(2) READ the CRC and validate the data***

image text in transcribed here is a screenshot of my Visual Studio

you can see the existing code, on the righthand side I have the CRC setup with the proper Header and Assembly.

image text in transcribed

----Here is the RAW Code file "bad network"----

// BadNetwork.cpp : This file contains the 'main' function. Program execution begins and ends there.

//

#include

#include

#include

#include "../crc/crc8.h"

#define NETWORK_QUALITY 3

char network[4096];

typedef struct _packet {

char counter;

char checksum;

} packet;

int gcu_send(packet* p) {

if ((rand() % 10) % NETWORK_QUALITY == 0) {

printf("\tInserting a bit error... ");

p->counter |= (1

}

memcpy(network, p, sizeof(packet));

return 0;

}

int gcu_recv(packet* p) {

memcpy(p, network, sizeof(packet));

memset(network, 0, 4096);

return 0;

}

int task1_counter = 0;

int task1() {

printf("Counter is %d ", task1_counter);

packet p;

gcu_recv(&p);

// TODO: Only increment the task1_counter if the CRC is good/valid.

printf("incrementing by %d ", p.counter);

task1_counter += p.counter;

// END TODO

return task1_counter;

}

int task2() {

packet p;

p.counter = 1;

// TODO: Insert the CRC on the packet

gcu_send(&p);

printf("Sending new message. ");

return 0;

}

int cooperative_scheduler() {

while (1) {

task1();

task2();

Sleep(1000);

}

return 0;

}

int main()

{

time_t t;

srand((unsigned)time(&t));

printf("Starting the GCU Cooperative Scheduler. Press Ctrl-C to exit.");

cooperative_scheduler();

}

----Here is the RAW Assembly Code----

TITLE crc8.obj

.686P

.XMM

include listing.inc

.model flat

INCLUDELIB LIBCMT

INCLUDELIB OLDNAMES

PUBLIC _crc8

_TEXT SEGMENT

_data$ = 8 ; size = 4

_length$ = 12 ; size = 4

_crc8 PROC

; 4 : {

push edi

; 6 : char extract;

; 7 : char sum;

; 8 : for (int i = 0; i

mov edi, DWORD PTR _length$[esp]

xor al, al

test edi, edi

jle SHORT $LN3@crc8

; 5 : char crc = 0x00;

push ebx

push esi

mov esi, DWORD PTR _data$[esp+8]

$LL4@crc8:

; 9 : {

; 10 : extract = *data;

mov bl, BYTE PTR [esi]

; 11 : for (char tempI = 8; tempI; tempI--)

mov dh, 8

$LL7@crc8:

; 12 : {

; 13 : sum = (crc ^ extract) & 0x01;

mov cl, al

mov dl, bl

xor dl, al

sar cl, 1

; 14 : crc >>= 1;

; 15 : if (sum)

; 16 : crc ^= 0x8C;

; 17 : extract >>= 1;

mov al, cl

movzx ecx, cl

xor al, -116 ; ffffff8cH

and dl, 1

movzx eax, al

cmove eax, ecx

sar bl, 1

add dh, -1

jne SHORT $LL7@crc8

; 18 : }

; 19 : data++;

inc esi

sub edi, 1

jne SHORT $LL4@crc8

; 20 : }

; 21 : return crc;

pop esi

pop ebx

$LN3@crc8:

; 22 : }

pop edi

ret 0

_crc8 ENDP

_TEXT ENDS

END

----Here is the RAW Code for Header----

#pragma once

char crc8(const char* data, int length);

int task20{ packet p; p. counter =1; // TODO: Insert the CRC on the packet gcu_send(\&p); char crc8( const char* data, int length); printf("Sending new message. ); return ; +t badnetwork.c (Global Scope) - Q task10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago