master/device_id.c
author Florian Pose <fp@igh-essen.com>
Mon, 05 Mar 2007 09:55:39 +0000
changeset 610 29489a43ecee
parent 577 db34078f34cc
permissions -rw-r--r--
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
slave->online to ec_online_state and introduced
ec_slave_set_app_state().
575
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT device ID.
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/list.h>
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/netdevice.h>
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "globals.h"
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "device_id.h"
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/*****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
static int ec_device_id_parse_mac(ec_device_id_t *dev_id,
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        const char *src, const char **remainder)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
{
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
    unsigned int i, value;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
    char *rem;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
    for (i = 0; i < ETH_ALEN; i++) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        value = simple_strtoul(src, &rem, 16);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        if (rem != src + 2
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
                || value > 0xFF
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
                || (i < ETH_ALEN - 1 && *rem != ':')) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
            return -1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        dev_id->octets[i] = value;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        if (i < ETH_ALEN - 1)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
            src = rem + 1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    dev_id->type = ec_device_id_mac;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    *remainder = rem;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    return 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
}
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
/*****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
void ec_device_id_clear_list(struct list_head *ids)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
{
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    ec_device_id_t *dev_id, *next_dev_id;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    list_for_each_entry_safe(dev_id, next_dev_id, ids, list) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        list_del(&dev_id->list);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        kfree(dev_id);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
}
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
/*****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
static int ec_device_id_create_list(struct list_head *ids, const char *src)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
{
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    const char *rem;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    ec_device_id_t *dev_id;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    unsigned int index = 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    while (*src) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        // allocate new device ID
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        if (!(dev_id = kmalloc(sizeof(ec_device_id_t), GFP_KERNEL))) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
            EC_ERR("Out of memory!\n");
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
            goto out_free;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        if (*src == ';') { // empty device ID
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
            dev_id->type = ec_device_id_empty;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
        else if (*src == 'M') {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
            src++;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
            if (ec_device_id_parse_mac(dev_id, src, &rem)) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
                EC_ERR("Device ID %u: Invalid MAC syntax!\n", index);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
                kfree(dev_id);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
                goto out_free;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
            }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
            src = rem;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        else {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
            EC_ERR("Device ID %u: Unknown format \'%c\'!\n", index, *src);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
            kfree(dev_id);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
            goto out_free;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
        list_add_tail(&dev_id->list, ids); 
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
        if (*src) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
            if (*src != ';') {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
                EC_ERR("Invalid delimiter '%c' after device ID %i!\n",
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
                        *src, index);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
                goto out_free;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
            }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
            src++; // skip delimiter
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
        index++;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    return 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
out_free:
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    ec_device_id_clear_list(ids);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    return -1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
}
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
/*****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
int ec_device_id_process_params(const char *main, const char *backup,
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        struct list_head *main_ids, struct list_head *backup_ids)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
{
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    ec_device_id_t *id;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    unsigned int main_count = 0, backup_count = 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    if (ec_device_id_create_list(main_ids, main))
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
        return -1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    if (ec_device_id_create_list(backup_ids, backup))
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        return -1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    // count main device IDs and check for empty ones
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    list_for_each_entry(id, main_ids, list) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        if (id->type == ec_device_id_empty) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
            EC_ERR("Main device IDs may not be empty!\n");
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
            return -1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
        main_count++;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    // count backup device IDs
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    list_for_each_entry(id, backup_ids, list) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
        backup_count++;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    // fill up backup device IDs
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    while (backup_count < main_count) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        if (!(id = kmalloc(sizeof(ec_device_id_t), GFP_KERNEL))) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
            EC_ERR("Out of memory!\n");
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
            return -1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        id->type = ec_device_id_empty;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        list_add_tail(&id->list, backup_ids);
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        backup_count++;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    return 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
}
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
/*****************************************************************************/
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
int ec_device_id_check(const ec_device_id_t *dev_id,
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
        const struct net_device *dev, const char *driver_name,
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
        unsigned int device_index)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
{
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    unsigned int i;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    switch (dev_id->type) {
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
        case ec_device_id_mac:
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
            for (i = 0; i < ETH_ALEN; i++)
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
                if (dev->dev_addr[i] != dev_id->octets[i])
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
                    return 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
            return 1;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
        default:
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
            return 0;
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    }
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
}
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
                
9a2121b500b1 Layed out device ID functionality in own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
/*****************************************************************************/
577
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   200
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   201
ssize_t ec_device_id_print(const ec_device_id_t *dev_id, char *buffer)
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   202
{
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   203
    off_t off = 0;
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   204
    unsigned int i;
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   205
    
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   206
    switch (dev_id->type) {
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   207
        case ec_device_id_empty:
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   208
            off += sprintf(buffer + off, "none");
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   209
            break;
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   210
        case ec_device_id_mac:
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   211
            off += sprintf(buffer + off, "MAC ");
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   212
            for (i = 0; i < ETH_ALEN; i++) {
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   213
                off += sprintf(buffer + off, "%02X", dev_id->octets[i]);
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   214
                if (i < ETH_ALEN - 1) off += sprintf(buffer + off, ":");
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   215
            }
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   216
            break;
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   217
    }
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   218
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   219
    return off;
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   220
}
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   221
                
db34078f34cc Added ec_device_id_print().
Florian Pose <fp@igh-essen.com>
parents: 575
diff changeset
   222
/*****************************************************************************/