13 int ngadmin_scan (struct ngadmin *nga)
19 sent by official win client:
35 static const unsigned short hello[] = {
58 /* create attributes for an "hello" request */
59 attr = createEmptyList();
61 pushBackList(attr, newEmptyAttr(hello[i]));
62 if (hello[i] == ATTR_END)
66 /* send request to all potential switches */
67 i = sendNgPacket(nga, CODE_READ_REQ, attr);
68 clearList(attr, (void(*)(void*))freeAttr);
74 /* try to receive any packets until timeout */
75 swiList = createEmptyList();
76 /* FIXME: end after timeout whatever received packet is good or not */
77 while (recvNgPacket(nga, CODE_READ_REP, NULL, NULL, attr) >= 0) {
78 sa = malloc(sizeof(struct swi_attr));
81 extractSwitchAttributes(sa, attr);
82 clearList(attr, (void(*)(void*))freeAttr);
83 pushBackList(swiList, sa);
86 nga->swi_count = swiList->count;
87 nga->swi_tab = convertToArray(swiList, sizeof(struct swi_attr));
88 destroyList(swiList, free);
89 destroyList(attr, (void(*)(void*))freeAttr);
96 const struct swi_attr* ngadmin_getSwitchTab (struct ngadmin *nga, int *nb)
98 if (nga == NULL || nb == NULL)
101 *nb = nga->swi_count;
107 const struct swi_attr* ngadmin_getCurrentSwitch (struct ngadmin *nga)
116 int ngadmin_login (struct ngadmin *nga, int id)
126 else if (id < 0 || id >= nga->swi_count)
129 sa = &nga->swi_tab[id];
131 nga->encrypt_pass = false;
133 attr = createEmptyList();
134 pushBackList(attr, newEmptyAttr(ATTR_ENCPASS));
135 ret = readRequest(nga, attr);
139 filterAttributes(attr, ATTR_ENCPASS, ATTR_END);
140 if (attr->first != NULL) {
141 at = attr->first->data;
142 nga->encrypt_pass = (at->size == 4 && ntohl(*(unsigned int*)at->data) == 1);
144 clearList(attr, (void(*)(void*))freeAttr);
146 /* Strangely, passwords must never be encrypted inside a read request,
147 * or it will be rejected. Seems more to be a firmware bug. */
148 pushBackList(attr, newAttr(ATTR_PASSWORD, strlen(nga->password), strdup(nga->password)));
149 ret = readRequest(nga, attr);
150 if (ret == ERR_OK ) {
151 /* login succeeded */
152 /* TODO: if keep broadcasting is disabled, connect() the UDP
153 socket so icmp errors messages (port unreachable, TTL exceeded
154 in transit, ...) can be received */
161 destroyList(attr, (void(*)(void*))freeAttr);