Hi all,
I have a question concerning the implementation of an interface between two layers of a network stack (see extract of the subsequent stack). Furthermore I am thankful for some hints how to implement frames in C.
Stack and Frames:
...
++++++++++++++
+ Layer n+1 +
++++++++++++++
+ Layer n +
++++++++++++++
...
E.g. Layer n+1 defines the following sample (simple;) frame (FRAME)
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++
+ sourceAddress | destinationAddr ess | control | payload +
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++
with the following conditions:
* 8 bit sourceAddress field,
* 8 bit destinationAddr ess field,
* 8 bit control field and
* a payload field with variable length
First of all: the implementation should be in ANSI C.
How is it a good way to implement the frame? Should I implement it using C-structures, e.g.:
struct FRAME {
unsigned char sourceAddress;
unsigned char destinationAddr ess;
unsigned char control;
void *payload
};
or maybe like this:
struct FRAME {
unsigned char sourceAddress;
unsigned char destinationAddr ess;
unsigned char control;
};
Is it a good idea to take the payload (pointer) also to the struct? Are there better ways to implement it? Any idea is welcome!
The next problem, which also concerns the realization of the implementation of a frame, is as follows: How to make a good interface between two layers, e.g. layer n+1 and layer n. How should a frame be passed to next lower/higher layer? I thought about the following (but I am not sure if it is a good way...):
struct DATA {
unsigned int bufferSize; /* size of the buffer, i.e. header and payload (which could be variable) */
void *buffer; /* contains the complete frame */
};
/* send functions */
int sendDataDownToL owerLayer(struc t DATA *a);
int sendDataUpToHig herLayer(struct DATA *a);
/* receive functions */
int receiveDataFrom LowerLayer(stru ct DATA *a);
int receiveDataFrom HigherLayer(str uct DATA *a);
What do you think about this approach? I never implemented a network stack so I don“t have any experience... If you have any idea, hints, ... just let me know!!!
Thank you in advance,
svkers
I have a question concerning the implementation of an interface between two layers of a network stack (see extract of the subsequent stack). Furthermore I am thankful for some hints how to implement frames in C.
Stack and Frames:
...
++++++++++++++
+ Layer n+1 +
++++++++++++++
+ Layer n +
++++++++++++++
...
E.g. Layer n+1 defines the following sample (simple;) frame (FRAME)
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++
+ sourceAddress | destinationAddr ess | control | payload +
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++
with the following conditions:
* 8 bit sourceAddress field,
* 8 bit destinationAddr ess field,
* 8 bit control field and
* a payload field with variable length
First of all: the implementation should be in ANSI C.
How is it a good way to implement the frame? Should I implement it using C-structures, e.g.:
struct FRAME {
unsigned char sourceAddress;
unsigned char destinationAddr ess;
unsigned char control;
void *payload
};
or maybe like this:
struct FRAME {
unsigned char sourceAddress;
unsigned char destinationAddr ess;
unsigned char control;
};
Is it a good idea to take the payload (pointer) also to the struct? Are there better ways to implement it? Any idea is welcome!
The next problem, which also concerns the realization of the implementation of a frame, is as follows: How to make a good interface between two layers, e.g. layer n+1 and layer n. How should a frame be passed to next lower/higher layer? I thought about the following (but I am not sure if it is a good way...):
struct DATA {
unsigned int bufferSize; /* size of the buffer, i.e. header and payload (which could be variable) */
void *buffer; /* contains the complete frame */
};
/* send functions */
int sendDataDownToL owerLayer(struc t DATA *a);
int sendDataUpToHig herLayer(struct DATA *a);
/* receive functions */
int receiveDataFrom LowerLayer(stru ct DATA *a);
int receiveDataFrom HigherLayer(str uct DATA *a);
What do you think about this approach? I never implemented a network stack so I don“t have any experience... If you have any idea, hints, ... just let me know!!!
Thank you in advance,
svkers
Comment