summaryrefslogtreecommitdiff
path: root/cleopatre/application/spidlib/src/eoc.c
blob: 5029476252c71ce46aecdb3fe95d259bb5f8d5fa (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
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
/* SPC300 bundle {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    application/spidlib/src/eoc.c
 * \brief   EoC-specific functions
 * \ingroup spidlib
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include "spidlib.h"

#ifdef __UTESTS__
    #include "eoc_utests.h"
#endif  /* __UTESTS__ */

/**
 * Reboots the slave with MAC address given as parameter.
 * \param mac_address MAC address of the slave to reboot
 * \return error type (SPIDLIB_SUCCESS if success)
 * \return SPIDLIB_ERROR_PARAM: bad input parameter
 * \return SPIDLIB_ERROR_SYSTEM: system error, see errno
 */

spidlib_error_t spidlib_eoc_reboot(char *mac_address)
{
    return SPIDLIB_SUCCESS;
}

/**
 * Returns list of MAC addresses of online slaves and number of online slaves.
 * \param mac_address_list pointer to store the list of MAC addresses
 * \param mac_address_count pointer to store number of online slaves
 * \return error type (SPIDLIB_SUCCESS if success)
 * \return SPIDLIB_ERROR_PARAM: bad input parameters
 * \return SPIDLIB_ERROR_SYSTEM: system error, see errno
 */

extern spidlib_error_t spidlib_eoc_get_topo(char *mac_address_list, int *mac_address_count)
{
    const char delimiters[2] = SPIDLIB_EOC_ONLINE_INFO_DELIMITER "\0";
    char key[SPIDLIB_KEY_MAX_LEN] = {0};
    unsigned int elt_number = SPIDLIB_ELT_MAX_NB;
    char *elt[SPIDLIB_ELT_MAX_NB] = {0};
    char buffer[SPIDLIB_LINE_MAX_LEN] = {0};
    spidlib_error_t error = SPIDLIB_SUCCESS;

    /* check input parameters */
    if ( (mac_address_list == NULL) || (mac_address_count == NULL) )
        return SPIDLIB_ERROR_PARAM;

    /* skim through lines of online info file */
    for (*mac_address_count=0; *mac_address_count<SPIDLIB_EOC_ONLINE_INFO_LINE_MAX_NB; (*mac_address_count)++)
    {
        /* get current line key */
        if ( (error = spidlib_config_read_line(SPIDLIB_EOC_ONLINE_INFO_PATH, delimiters, key, &elt_number, elt, buffer, SPIDLIB_LINE_MAX_LEN)) < 0 )
            return error;

        /* check that eof is not reached */
        if (!strcmp(key, ""))
            break;

        /* convert mac address from string to char array */
        if ( (error = spidlib_mac_str_to_bin(key, (unsigned char *)mac_address_list+SPIDLIB_MAC_BIN_LEN*(*mac_address_count))) < 0 )
            return error;
	}

    return SPIDLIB_SUCCESS;
}

/**
 * Returns real-time statistics of a slave with given MAC address.
 * \param mac_address MAC address of the slave
 * \param eoc_rt_stat pointer to structure for storing real-time statistics
 * \return error type (SPIDLIB_SUCCESS if success)
 * \return SPIDLIB_ERROR_PARAM: bad input parameters
 * \return SPIDLIB_ERROR_SYSTEM: system error, see errno
 */

extern spidlib_error_t spidlib_eoc_get_stat(char *mac_address, spidlib_eoc_rt_stat_t *eoc_rt_stat)
{
    return SPIDLIB_SUCCESS;
}

/**
 * Resets real-time statistics of a slave with given MAC address.
 * \param mac_address MAC address of the slave
 * \return error type (SPIDLIB_SUCCESS if success)
 * \return SPIDLIB_ERROR_PARAM: bad input parameters
 * \return SPIDLIB_ERROR_SYSTEM: system error, see errno
 */

extern spidlib_error_t spidlib_eoc_reset_stat(char *mac_address)
{
    return SPIDLIB_SUCCESS;
}

/**
 * Returns device information for a slave with given MAC address.<BR>
 * Device information includes: model number, port amount and authorization state.
 * \param mac_address MAC address of the slave
 * \param eoc_dev_info pointer to structure for storing device information
 * \return error type (SPIDLIB_SUCCESS if success)
 * \return SPIDLIB_ERROR_PARAM: bad input parameters
 * \return SPIDLIB_ERROR_SYSTEM: system error, see errno
 */

extern spidlib_error_t spidlib_eoc_get_device_info(char *mac_address, spidlib_eoc_dev_info_t *eoc_dev_info)
{
    return SPIDLIB_SUCCESS;
}

/**
 * Returns link quality for a slave with given MAC address.<BR>
 * Link quality includes: downstream and upstream attenuation and downstream
 * and upstream quality.
 * \param mac_address MAC address of the slave
 * \param eoc_link_quality pointer to structure for storing link quality
 * \return error type (SPIDLIB_SUCCESS if success)
 * \return SPIDLIB_ERROR_PARAM: bad input parameters
 * \return SPIDLIB_ERROR_SYSTEM: system error, see errno
 */

extern spidlib_error_t spidlib_eoc_get_link(char *mac_address, spidlib_eoc_link_quality_t *eoc_link_quality)
{
    return SPIDLIB_SUCCESS;
}