5 #include <nsdp/protocol.h>
11 int ngadmin_getPortsStatus (struct ngadmin *nga, unsigned char *ports)
17 struct attr_port_status *ps;
21 if (nga == NULL || ports == NULL)
28 attr = createEmptyList();
29 pushBackList(attr, newEmptyAttr(ATTR_PORT_STATUS));
30 ret = readRequest(nga, attr);
34 filterAttributes(attr, ATTR_PORT_STATUS, ATTR_END);
36 memset(ports, SPEED_UNK, sa->ports);
38 for (ln = attr->first; ln != NULL; ln = ln->next) {
41 if (ps->port <= sa->ports)
42 ports[ps->port - 1] = ps->status;
46 destroyList(attr, (void(*)(void*))freeAttr);
53 int ngadmin_getPortsStatistics (struct ngadmin *nga, struct port_stats *ps)
59 struct attr_port_stat *aps;
63 if (nga == NULL || ps == NULL)
70 attr = createEmptyList();
71 pushBackList(attr, newEmptyAttr(ATTR_PORT_STATISTICS));
72 ret = readRequest(nga, attr);
76 filterAttributes(attr, ATTR_PORT_STATISTICS, ATTR_END);
78 memset(ps, 0, sa->ports * sizeof(struct port_stats));
80 for (ln = attr->first; ln != NULL; ln = ln->next) {
83 if (aps->port <= sa->ports) {
84 ps[aps->port -1].recv = aps->recv;
85 ps[aps->port -1].sent = aps->sent;
86 ps[aps->port -1].crc = aps->crc;
91 destroyList(attr, (void(*)(void*))freeAttr);
98 int ngadmin_resetPortsStatistics (struct ngadmin *nga)
103 attr = createEmptyList();
104 pushBackList(attr, newByteAttr(ATTR_STATS_RESET, 1));
107 return writeRequest(nga, attr);
111 int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb)
117 struct attr_cabletest_do *acd;
118 struct attr_cabletest_result *acr;
121 if (nga == NULL || ct == NULL)
123 else if (nga->current == NULL)
127 attr = createEmptyList();
129 for (i = 0; i < nb; i++) {
131 acd = malloc(sizeof(struct attr_cabletest_do));
134 acd->port = ct[i].port;
136 pushBackList(attr, newAttr(ATTR_CABLETEST_DO, sizeof(struct attr_cabletest_do), acd));
138 ret = writeRequest(nga, attr);
143 /* the list is destroyed by writeRequest, so we need to recreate it */
144 attr = createEmptyList();
145 pushBackList(attr, newByteAttr(ATTR_CABLETEST_RESULT, ct[i].port));
146 ret = readRequest(nga, attr);
150 filterAttributes(attr, ATTR_CABLETEST_RESULT, ATTR_END);
152 for (ln = attr->first; ln != NULL; ln = ln->next) {
155 if (at->size == sizeof(struct attr_cabletest_result) && acr->port == ct[i].port) {
162 /* just empty the list, it will be used at next iteration */
163 clearList(attr, (void(*)(void*))freeAttr);
168 destroyList(attr, (void(*)(void*))freeAttr);