summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/Mtftp4Dxe/Mtftp4Option.h
blob: 5f37b0f7b9e6aa74466c3b54c8c3d1ed7a901c21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/** @file
  Routines to process MTFTP4 options.

Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/


#ifndef __EFI_MTFTP4_OPTION_H__
#define __EFI_MTFTP4_OPTION_H__

#define MTFTP4_SUPPORTED_OPTIONS  5
#define MTFTP4_OPCODE_LEN         2
#define MTFTP4_ERRCODE_LEN        2
#define MTFTP4_BLKNO_LEN          2
#define MTFTP4_DATA_HEAD_LEN      4

#define MTFTP4_BLKSIZE_EXIST      0x01
#define MTFTP4_TIMEOUT_EXIST      0x02
#define MTFTP4_TSIZE_EXIST        0x04
#define MTFTP4_MCAST_EXIST        0x08
#define MTFTP4_WINDOWSIZE_EXIST   0x10

typedef struct {
  UINT16                    BlkSize;
  UINT16                    WindowSize;
  UINT8                     Timeout;
  UINT32                    Tsize;
  IP4_ADDR                  McastIp;
  UINT16                    McastPort;
  BOOLEAN                   Master;
  UINT32                    Exist;
} MTFTP4_OPTION;

/**
  Allocate and fill in a array of Mtftp options from the Packet.

  It first calls Mtftp4FillOption to get the option number, then allocate
  the array, at last, call Mtftp4FillOption again to save the options.

  @param  Packet                 The packet to parse
  @param  PacketLen              The length of the packet
  @param  OptionCount            The number of options in the packet
  @param  OptionList             The point to get the option array.

  @retval EFI_INVALID_PARAMETER  The parametera are invalid or packet isn't a
                                 well-formatted OACK packet.
  @retval EFI_SUCCESS            The option array is build
  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory for the array

**/
EFI_STATUS
Mtftp4ExtractOptions (
  IN     EFI_MTFTP4_PACKET     *Packet,
  IN     UINT32                PacketLen,
     OUT UINT32                *OptionCount,
     OUT EFI_MTFTP4_OPTION     **OptionList        OPTIONAL
  );

/**
  Parse the option in Options array to MTFTP4_OPTION which program
  can access directly.

  @param  Options                The option array, which contains addresses of each
                                 option's name/value string.
  @param  Count                  The number of options in the Options
  @param  Request                Whether this is a request or OACK. The format of
                                 multicast is different according to this setting.
  @param  Operation              The current performed operation.
  @param  MtftpOption            The MTFTP4_OPTION for easy access.

  @retval EFI_INVALID_PARAMETER  The option is malformatted
  @retval EFI_UNSUPPORTED        Some option isn't supported
  @retval EFI_SUCCESS            The option are OK and has been parsed.

**/
EFI_STATUS
Mtftp4ParseOption (
  IN     EFI_MTFTP4_OPTION     *Options,
  IN     UINT32                Count,
  IN     BOOLEAN               Request,
  IN     UINT16                Operation,
     OUT MTFTP4_OPTION         *MtftpOption
  );

/**
  Parse the options in the OACK packet to MTFTP4_OPTION which program
  can access directly.

  @param  Packet                 The OACK packet to parse
  @param  PacketLen              The length of the packet
  @param  Operation              The current performed operation.
  @param  MtftpOption            The MTFTP_OPTION for easy access.

  @retval EFI_INVALID_PARAMETER  The packet option is malformatted
  @retval EFI_UNSUPPORTED        Some option isn't supported
  @retval EFI_SUCCESS            The option are OK and has been parsed.

**/
EFI_STATUS
Mtftp4ParseOptionOack (
  IN     EFI_MTFTP4_PACKET     *Packet,
  IN     UINT32                PacketLen,
  IN     UINT16                Operation,
     OUT MTFTP4_OPTION         *MtftpOption
  );

extern CHAR8  *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS];

#endif