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) {
45 if (ps->port <= sa->ports)
46 ports[ps->port - 1] = ps->status;
50 destroyList(attr, (void(*)(void*))freeAttr);
57 int ngadmin_getPortsStatistics (struct ngadmin *nga, struct port_stats *ps)
63 struct attr_port_stat *aps;
67 if (nga == NULL || ps == NULL)
74 attr = createEmptyList();
75 pushBackList(attr, newEmptyAttr(ATTR_PORT_STATISTICS));
76 ret = readRequest(nga, attr);
80 filterAttributes(attr, ATTR_PORT_STATISTICS, ATTR_END);
82 memset(ps, 0, sa->ports * sizeof(struct port_stats));
84 for (ln = attr->first; ln != NULL; ln = ln->next) {
91 if (aps->port <= sa->ports) {
92 ps[aps->port -1].recv = aps->recv;
93 ps[aps->port -1].sent = aps->sent;
94 ps[aps->port -1].crc = aps->crc;
99 destroyList(attr, (void(*)(void*))freeAttr);
106 int ngadmin_resetPortsStatistics (struct ngadmin *nga)
111 attr = createEmptyList();
112 pushBackList(attr, newByteAttr(ATTR_STATS_RESET, 1));
115 return writeRequest(nga, attr);
119 int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb)
125 struct attr_cabletest_do *acd;
126 struct attr_cabletest_result *acr;
129 if (nga == NULL || ct == NULL)
131 else if (nga->current == NULL)
135 attr = createEmptyList();
137 for (i = 0; i < nb; i++) {
139 acd = malloc(sizeof(struct attr_cabletest_do));
142 acd->port = ct[i].port;
144 pushBackList(attr, newAttr(ATTR_CABLETEST_DO, sizeof(struct attr_cabletest_do), acd));
146 ret = writeRequest(nga, attr);
151 /* the list is destroyed by writeRequest, so we need to recreate it */
152 attr = createEmptyList();
153 pushBackList(attr, newByteAttr(ATTR_CABLETEST_RESULT, ct[i].port));
154 ret = readRequest(nga, attr);
158 filterAttributes(attr, ATTR_CABLETEST_RESULT, ATTR_END);
160 for (ln = attr->first; ln != NULL; ln = ln->next) {
163 if (at->size != sizeof(struct attr_cabletest_result)) {
167 if (acr->port == ct[i].port) {
174 /* just empty the list, it will be used at next iteration */
175 clearList(attr, (void(*)(void*))freeAttr);
180 destroyList(attr, (void(*)(void*))freeAttr);
187 int ngadmin_getLoopDetectionState (struct ngadmin *nga, int *s)
194 if (nga == NULL || s == NULL)
196 else if (nga->current == NULL)
199 attr = createEmptyList();
200 pushBackList(attr, newEmptyAttr(ATTR_LOOP_DETECT));
201 ret = readRequest(nga, attr);
205 filterAttributes(attr, ATTR_LOOP_DETECT, ATTR_END);
209 if (attr->first == NULL) {
213 at = attr->first->data;
218 *s = *(char *)at->data;
222 destroyList(attr, (void(*)(void*))freeAttr);
229 int ngadmin_setLoopDetectionState (struct ngadmin *nga, int s)
234 attr = createEmptyList();
235 pushBackList(attr, newByteAttr(ATTR_LOOP_DETECT, s != 0));
238 return writeRequest(nga, attr);