Simple mbed library with macros

Dependents:   SimpleTimer SimpleUART SimpleTimer Stoppuhr1

Committer:
Alkorin
Date:
Sat Nov 27 19:08:38 2010 +0000
Revision:
21:ce11d7ff88af
Added some Ethernet/IP structures

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alkorin 21:ce11d7ff88af 1 /*
Alkorin 21:ce11d7ff88af 2 * Copyright or © or Copr. 2010, Thomas SOETE
Alkorin 21:ce11d7ff88af 3 *
Alkorin 21:ce11d7ff88af 4 * Author e-mail: thomas@soete.org
Alkorin 21:ce11d7ff88af 5 * Library website : http://mbed.org/users/Alkorin/libraries/SimpleLib/
Alkorin 21:ce11d7ff88af 6 *
Alkorin 21:ce11d7ff88af 7 * This software is governed by the CeCILL license under French law and
Alkorin 21:ce11d7ff88af 8 * abiding by the rules of distribution of free software. You can use,
Alkorin 21:ce11d7ff88af 9 * modify and/ or redistribute the software under the terms of the CeCILL
Alkorin 21:ce11d7ff88af 10 * license as circulated by CEA, CNRS and INRIA at the following URL
Alkorin 21:ce11d7ff88af 11 * "http://www.cecill.info".
Alkorin 21:ce11d7ff88af 12 *
Alkorin 21:ce11d7ff88af 13 * As a counterpart to the access to the source code and rights to copy,
Alkorin 21:ce11d7ff88af 14 * modify and redistribute granted by the license, users are provided only
Alkorin 21:ce11d7ff88af 15 * with a limited warranty and the software's author, the holder of the
Alkorin 21:ce11d7ff88af 16 * economic rights, and the successive licensors have only limited
Alkorin 21:ce11d7ff88af 17 * liability.
Alkorin 21:ce11d7ff88af 18 *
Alkorin 21:ce11d7ff88af 19 * In this respect, the user's attention is drawn to the risks associated
Alkorin 21:ce11d7ff88af 20 * with loading, using, modifying and/or developing or reproducing the
Alkorin 21:ce11d7ff88af 21 * software by the user in light of its specific status of free software,
Alkorin 21:ce11d7ff88af 22 * that may mean that it is complicated to manipulate, and that also
Alkorin 21:ce11d7ff88af 23 * therefore means that it is reserved for developers and experienced
Alkorin 21:ce11d7ff88af 24 * professionals having in-depth computer knowledge. Users are therefore
Alkorin 21:ce11d7ff88af 25 * encouraged to load and test the software's suitability as regards their
Alkorin 21:ce11d7ff88af 26 * requirements in conditions enabling the security of their systems and/or
Alkorin 21:ce11d7ff88af 27 * data to be ensured and, more generally, to use and operate it in the
Alkorin 21:ce11d7ff88af 28 * same conditions as regards security.
Alkorin 21:ce11d7ff88af 29 *
Alkorin 21:ce11d7ff88af 30 * The fact that you are presently reading this means that you have had
Alkorin 21:ce11d7ff88af 31 * knowledge of the CeCILL license and that you accept its terms.
Alkorin 21:ce11d7ff88af 32 */
Alkorin 21:ce11d7ff88af 33
Alkorin 21:ce11d7ff88af 34 #ifndef __SIMPLELIB_ETHERNET_H__
Alkorin 21:ce11d7ff88af 35 #define __SIMPLELIB_ETHERNET_H__
Alkorin 21:ce11d7ff88af 36
Alkorin 21:ce11d7ff88af 37 typedef __packed struct {
Alkorin 21:ce11d7ff88af 38 char destination[6];
Alkorin 21:ce11d7ff88af 39 char source[6];
Alkorin 21:ce11d7ff88af 40 uint16_t type;
Alkorin 21:ce11d7ff88af 41 } ethernet_packet;
Alkorin 21:ce11d7ff88af 42 #define asETH(x) ((ethernet_packet*)(x))
Alkorin 21:ce11d7ff88af 43
Alkorin 21:ce11d7ff88af 44 #define IPV4_TYPE 0x0800
Alkorin 21:ce11d7ff88af 45 #define ARP_TYPE 0x0806
Alkorin 21:ce11d7ff88af 46
Alkorin 21:ce11d7ff88af 47 typedef __packed struct {
Alkorin 21:ce11d7ff88af 48 ethernet_packet eth;
Alkorin 21:ce11d7ff88af 49 __packed struct {
Alkorin 21:ce11d7ff88af 50 char hardware_type[2];
Alkorin 21:ce11d7ff88af 51 char protocol_type[2];
Alkorin 21:ce11d7ff88af 52 char hardware_size;
Alkorin 21:ce11d7ff88af 53 char protocol_size;
Alkorin 21:ce11d7ff88af 54 uint16_t opcode_request;
Alkorin 21:ce11d7ff88af 55 char sender_mac[6];
Alkorin 21:ce11d7ff88af 56 char sender_ip[4];
Alkorin 21:ce11d7ff88af 57 char target_mac[6];
Alkorin 21:ce11d7ff88af 58 char target_ip[4];
Alkorin 21:ce11d7ff88af 59 } arp;
Alkorin 21:ce11d7ff88af 60 } arp_packet;
Alkorin 21:ce11d7ff88af 61 #define asARP(x) ((arp_packet*)(x))
Alkorin 21:ce11d7ff88af 62
Alkorin 21:ce11d7ff88af 63 #define ARP_REQUEST 0x0001
Alkorin 21:ce11d7ff88af 64 #define ARP_REPLY 0x0002
Alkorin 21:ce11d7ff88af 65
Alkorin 21:ce11d7ff88af 66 #endif