This file is indexed.

/usr/include/tins/llc.h is in libtins-dev 1.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
 * Copyright (c) 2012, Matias Fontanini
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following disclaimer
 *   in the documentation and/or other materials provided with the
 *   distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef TINS_IEEE8022_H
#define TINS_IEEE8022_H

#include <list>
#include <vector>
#include <stdint.h>
#include "macros.h"
#include "pdu.h"
#include "endianness.h"

namespace Tins {

    /**
     * \brief Class representing a LLC frame.
     *
     * This PDU follows the standard LLC frame described in the IEEE 802.2 specs.
     */
    class LLC : public PDU {
    public:
        /**
         * \brief This PDU's flag.
         */
        static const PDU::PDUType pdu_flag = PDU::LLC;

    	/**
         * \brief Represents the LLC global DSAP address.
         */
        static const uint8_t GLOBAL_DSAP_ADDR;
        static const uint8_t NULL_ADDR;

        /**
         * \brief LLC Format flags.
         */
        enum Format {
            INFORMATION = 0,
            SUPERVISORY = 1,
            UNNUMBERED = 3
        };

        /**
         * \brief LLC Modifier functions.
         */
        enum ModifierFunctions {
        	UI = 0x00,
        	XID = 0x1D,
        	TEST = 0x07,
        	SABME = 0x1E,
        	DISC = 0x02,
        	UA = 0x06,
        	DM = 0x18,
        	FRMR = 0x11
        };

        /**
         * \brief LLC Supervisory functions
         */
        enum SupervisoryFunctions {
        	RECEIVE_READY = 0,
        	REJECT = 2,
        	RECEIVE_NOT_READY = 1
        };

        /**
         * \brief Default constructor.
         */
    	LLC();

    	/**
    	 * \brief Constructs an instance of LLC, setting the dsap and ssap.
    	 * The control field is set to 0.
    	 * \param dsap The dsap value to be set.
    	 * \param ssap The ssap value to be set.
    	 */
    	LLC(uint8_t dsap, uint8_t ssap);

        /**
         * \brief Constructs a LLC object from a buffer and adds all 
         * identifiable PDUs found in the buffer as children of this one.
         * 
         * If there is not enough size for a LLC header, a malformed_packet
         * exception is thrown.
         * 
         * \param buffer The buffer from which this PDU will be constructed.
         * \param total_sz The total size of the buffer.
         */
    	LLC(const uint8_t *buffer, uint32_t total_sz);

        /* Setters */

    	/**
		 * \brief Setter for the group destination bit.
		 * \param value The value to be set.
		 */
        void group(bool value);

        /**
		 * \brief Setter for the dsap field.
		 * \param new_dsap The new dsap field.
		 */
		void dsap(uint8_t new_dsap);

		/**
		 * \brief Setter for the response bit.
		 * \param value The value to be set.
		 */
		void response(bool value);

		/**
		 * \brief Setter for the ssap field.
		 * \param new_ssap The new ssap field.
		 */
		void ssap(uint8_t new_ssap);

		/**
		 * \brief Setter for the LLC frame format type.
		 * \param type The LLC frame format to set.
		 */
		void type(Format type);

		/**
		 * \brief Setter for sender send sequence number.
		 * 	Only applied if format is INFORMATION.
		 * \param seq_number New sender send sequence number to be set.
		 */
		void send_seq_number(uint8_t seq_number);

		/**
		 * \brief Setter for sender receive sequence number.
		 * 	Only applied if format is INFORMATION or SUPERVISORY.
		 * \param seq_number New sender receive sequence number to be set.
		 */
		void receive_seq_number(uint8_t seq_number);

		/**
		 * \brief Setter for the poll/final flag.
		 * \param value Bool indicating the value of the flag.
		 */
		void poll_final(bool value);

		/**
		 * \brief Setter for the supervisory function.
		 * Only applied if format is SUPERVISORY.
		 * \param new_func Value to set on the supervisory function field.
		 */
		void supervisory_function(SupervisoryFunctions new_func);

		/**
		 * \brief Setter for the modifier function field.
		 * Only applied if format is UNNUMBERED.
		 * \param modifier_func Value to set on the modifier function field.
		 */
		void modifier_function(ModifierFunctions mod_func);

		/**
		 * \brief Add a xid information field.
		 * Only applied if format is UNNUMBERED and function is XID.
		 * \param xid_id XID information of the MAC sublayer.
		 * \param llc_type_class Value to set the llc_type_class field.
		 * \param receive_window XID sender's receive window size.
		 */
		void add_xid_information(uint8_t xid_id, uint8_t llc_type_class, uint8_t receive_window);

		//TODO: Add Acknowledged connectionless information

        /* Getters */

		/**
		 * \brief Getter for the group destination bit.
		 * \return Whether the group bit is set or not.
		 */
		bool group() {return _header.dsap & 0x01; }

		/**
		 * \brief Getter for the dsap field.
		 * \return The dsap field value
		 */
		uint8_t dsap() {return _header.dsap; }

		/**
		 * \brief Getter for the response bit.
		 * \return Whether the response bit is set or not.
		 */
		bool response() {return (_header.ssap & 0x01); }

		/**
		 * \brief Getter for the ssap field.
		 * \return The ssap field.
		 */
		uint8_t ssap() {return _header.ssap; }

		/**
		 * \brief Getter for the LLC frame format type.
		 * \return The LLC frame format.
		 */
		uint8_t type() {return _type; }

		/**
		 * \brief Getter for sender send sequence number.
		 *
		 * \return The sender send sequence number if format is INFORMATION else 0.
		 */
		uint8_t send_seq_number() {
			return (type() == INFORMATION) ? (control_field.info.send_seq_num) : 0;
		}

		/**
		 * \brief Getter for sender receive sequence number.
		 *
		 * \return 	The sender receive sequence number if format is
		 * 			INFORMATION or SUPERVISORY else 0.
		 */
		uint8_t receive_seq_number() {
			switch (type()) {
				case INFORMATION:
					return control_field.info.recv_seq_num;
				case SUPERVISORY:
					return control_field.super.recv_seq_num;
				case UNNUMBERED:
					return 0;
                default:
                    return 0;
			}
		}

		/**
		 * \brief Getter for the poll/final flag.
		 * \return Whether the poll/final flag is set.
		 */
		bool poll_final() {
			switch (type()) {
				case UNNUMBERED:
					return control_field.unnumbered.poll_final_bit;
				case INFORMATION:
					return control_field.info.poll_final_bit;
				case SUPERVISORY:
					return control_field.super.poll_final_bit;
                default:
                    return false;
			}
		}

		/**
		 * \brief Getter for the supervisory function.
		 *
		 * \return The supervisory function if format is SUPERVISORY else 0.
		 */
		uint8_t supervisory_function() {
			if (type() == SUPERVISORY)
				return control_field.super.supervisory_func;
			return 0;
		}

		/**
		 * \brief Getter for the modifier function field.
		 *
		 * \return The modifier function if format is UNNUMBERED else 0.
		 */
		uint8_t modifier_function() {
			if (type() == UNNUMBERED)
				return (control_field.unnumbered.mod_func1 << 3) + control_field.unnumbered.mod_func2;
			return 0;
		}

        /**
         * \brief Returns the LLC frame's header length.
         *
         * \return The header's size.
         * \sa PDU::header_size()
         */
        uint32_t header_size() const;

        /**
         * \brief Getter for the PDU's type.
         * \sa PDU::pdu_type
         */
        PDUType pdu_type() const { return PDU::LLC; }

        /**
		 * \brief Delete all the information fields added.
		 */
		void clear_information_fields();

        /**
         * \brief Clones this PDU.
         *
         * \sa PDU::clone
         */
        LLC *clone() const {
            return new LLC(*this);
        }
    private:
        TINS_BEGIN_PACK
        struct llchdr {
            uint8_t dsap;
            uint8_t ssap;
        } TINS_END_PACK;

        #if TINS_IS_LITTLE_ENDIAN
            TINS_BEGIN_PACK
            struct info_control_field {
                uint16_t
                            type_bit:1,
                            send_seq_num:7,
                            poll_final_bit:1,
                            recv_seq_num:7;
            } TINS_END_PACK;

            TINS_BEGIN_PACK
            struct super_control_field {
                uint16_t	type_bit:2,
                            supervisory_func:2,
                            unused:4,
                            poll_final_bit:1,
                            recv_seq_num:7;
            } TINS_END_PACK;

            TINS_BEGIN_PACK
            struct un_control_field {
                uint8_t		type_bits:2,
                            mod_func1:2,
                            poll_final_bit:1,
                            mod_func2:3;
            } TINS_END_PACK;
        #elif TINS_IS_BIG_ENDIAN
            TINS_BEGIN_PACK
            struct info_control_field {
                uint16_t    send_seq_num:7,
                            type_bit:1,
                            recv_seq_num:7,
                            poll_final_bit:1;
            } TINS_END_PACK;

            TINS_BEGIN_PACK
            struct super_control_field {
                uint16_t	unused:4,
                            supervisory_func:2,
                            type_bit:2,
                            recv_seq_num:7,
                            poll_final_bit:1;
            } TINS_END_PACK;

            TINS_BEGIN_PACK
            struct un_control_field {
                uint8_t		mod_func2:3,
                            poll_final_bit:1,
                            mod_func1:2,
                            type_bits:2;
            } TINS_END_PACK;
        #endif
        
        typedef std::vector<uint8_t> field_type;

        void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);

        llchdr _header;
        uint8_t control_field_length;
        union {
        	info_control_field info;
        	super_control_field super;
        	un_control_field unnumbered;
        } control_field;
        Format _type;
        uint8_t information_field_length;
        std::list<field_type> information_fields;
    };

}

#endif // TINS_IEEE8022_H