NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
WindowScale.c
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "TCP.h"
16#include "TCP_Header.h"
17
18void set_window_scaling(PNETSIM_SOCKET s, PWsopt opt)
19{
20 if (opt)
21 {
22 s->tcb->isWindowScaling = true;
23 s->tcb->Snd.Wind_Shift = opt->Shift_cnt;
24 s->tcb->Rcv.Wind_Shift = opt->Shift_cnt;
25 s->tcb->RCV.WND = s->tcb->get_RCVWND(s);
26 }
27 else
28 {
29 s->tcb->isWindowScaling = false;
30 s->tcb->Snd.Wind_Shift = 0;
31 s->tcb->Rcv.Wind_Shift = 0;
32 }
33}
34
35UINT8 get_shift_count(PNETSIM_SOCKET s)
36{
37 return s->tcb->isWindowScaling ? s->tcb->Snd.Wind_Shift : 0;
38}
39
40void set_window_scaling_option(PNETSIM_SOCKET s, PTCP_DEV_VAR tcp)
41{
42 if (tcp->isWindowScaling)
43 {
44 s->tcb->isWindowScaling = true;
45 s->tcb->Snd.Wind_Shift = tcp->shiftCount;
46 s->tcb->Rcv.Wind_Shift = tcp->shiftCount;
47 }
48}
49
50UINT32 window_scale_get_cwnd(PNETSIM_SOCKET s)
51{
52 UINT32 c = (UINT32)s->tcb->get_WND(s);
53 if (s->tcb->isWindowScaling)
54 {
55 UINT32 r = c << s->tcb->Snd.Wind_Shift;
56 UINT32 mss = s->tcb->get_MSS(s);
57 return max(r, mss);
58 }
59 else
60 return (c);
61}
62
63UINT16 window_scale_get_wnd(PNETSIM_SOCKET s)
64{
65 if (s->tcb->isWindowScaling)
66 return (UINT16)(s->tcb->SND.WND >> s->tcb->Snd.Wind_Shift);
67 else
68 return (UINT16)(s->tcb->SND.WND);
69}