CC=gcc
-CFLAGS=-I.
-DEPS =
+CFLAGS=-Wall -std=c99
+DEPS =
OBJ = socket.o main.o gs105e.o shell.o shell_ip.o shell_vlan.o shell_sys.o shell_port.o
%.o: %.c $(DEPS)
#include <stdio.h>
#include <stdlib.h>
-unsigned char * gs105e_queryData;
-unsigned int gsDataLen;
+char * gs105e_queryData;
+int gsDataLen;
struct vlan * getVlanSetting(unsigned int vlanId) {
struct vlan * _vlan = settings.vlans;
- gs105e_queryData = (unsigned char * )realloc(gs105e_queryData, sizeof(char) * 32);
+ gs105e_queryData = realloc(gs105e_queryData, sizeof(char) * 32);
gsDataLen = 32;
emptyBuffer();
gs105e_queryData[23] = newPacketId();
- if (gs105e_queryData[gsDataLen - 4] != 0xFF | gs105e_queryData[gsDataLen - 3] != 0xFF | gs105e_queryData[gsDataLen - 2] != 0x00 | gs105e_queryData[gsDataLen - 1] != 0x00)
+ if ((gs105e_queryData[gsDataLen - 4] != 0xFF) | (gs105e_queryData[gsDataLen - 3] != 0xFF) | (gs105e_queryData[gsDataLen - 2] != 0x00) | (gs105e_queryData[gsDataLen - 1] != 0x00))
addData("\xFF\xFF\x00\x00", 4);
sendBroadcast(gs105e_queryData, gsDataLen);
// printf("Received No or Invalid Packet\n");
return -1;
}
- if (memcmp(&data[8], myMac, 6) | data[0] != 0x01 | (!(data[1] == 0x02 | data[1] == 0x04))) {
+ if (memcmp(&data[8], myMac, 6) | (data[0] != 0x01) | (!((data[1] == 0x02) | (data[1] == 0x04)))) {
return -1;
}
// printf("Received No or Invalid Packet\n");
return -1;
}
- if (memcmp(&data[8], myMac, 6) | data[0] != 0x01 | (!(data[1] == 0x02 | data[1] == 0x04))) {
+ if (memcmp(&data[8], myMac, 6) | (data[0] != 0x01) | (!((data[1] == 0x02) | (data[1] == 0x04)))) {
gs105e_actRecv();
return -1;
}
return gs105e_act();
}
-int gs105e_restart(int vlanId) {
+int gs105e_restart(void) {
makeHeader(QR_EXEC);
char data[1] = {1};
void makeHeader(unsigned int queryType);
void gs105e_query (void);
+void gs105e_queryAll(void);
int gs105e_addVlan(int vlanId) ;
int gs105e_delVlan(int vlanId) ;
+int gs105e_setVlanMembers(unsigned int vlanId, unsigned int members, unsigned int tagged);
+int gs105e_vlanEnable();
int gs105e_discover(void);
+int gs105e_restart(void);
int gs105e_setName(char * data);
+int gs105e_dhcpSettings(int action);
+
+int gs105e_cableDiagnostics(int port);
+int gs105e_mirrorPorts(int outputPort, int mirrorMask);
#endif
int main () {
- int n;
-
init_socket();
myMac = get_mac("eth0");
gs105e_init();
- shell();
+ return shell();
}
void shell_set(char ** argv, int elem) {
- int n;
if (strncmp(argv[1], "name", 4) == 0) {
if (elem != 3) {
printf("set name [name]\n");
#ifndef SHELL_H
#define SHELL_H
+#define _BSD_SOURCE
+
#include <stdio.h>
#include "socket.h"
#include "gs105e.h"
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <pwd.h>
void printIp(char * data);
void shell_port(char ** argv, int elem);
void shell_sys(char ** argv, int elem);
+void shell_vlan(char **argv, int elem);
#endif
#include "shell.h"
void shell_ip(char ** argv, int elem) {
- int n;
if (elem == 1) {
printf(" ip [show|dhcp|set] \n");
return;
if (strncmp(argv[1], "show", 4) == 0) {
printf("Port\tSpeed\t\tBytes In\t\tBytes Out\n");
for (n = 0; n< 5; n++) {
- printf("%i\t%s\t% 8lu\t\t% 8lu\n", n,
+ printf("%i\t%s\t%8lu\t\t%8lu\n", n,
(settings.portStatistics[n].state == 0x05 ? "1000 Mbit/s" : (settings.portStatistics[n].state == 0x04 ? "100 Mbit/s" : (settings.portStatistics[n].state == 0x03 ? "10 Mbit/s": (settings.portStatistics[n].state == 0x00 ? "No Cable": "???")))),
settings.portStatistics[n].bytesIn,
settings.portStatistics[n].bytesOut
n = atoi(argv[2]);
- if (n < 1 | n > 5) {
+ if ((n < 1) | (n > 5)) {
printf("Invalid Port\n");
return;
}
n = atoi(argv[2]);
- if (n < 1 | n > 5) {
+ if ((n < 1) | (n > 5)) {
printf("Invalid Port %i\n", n);
return;
}
for (m = 3; m < elem; m++) {
i = atoi(argv[m]);
- if (i < 1 | i > 5) {
+ if ((i < 1) | (i > 5)) {
printf("Invalid Port %i\n", i);
return;
}
void shell_sys(char ** argv, int elem) {
- int n, i, m, o;
if (elem == 1) {
printf(" sys [show|name|password|restart] \n");
while (vl != NULL) {
printf("%u\t", vl->id);
for (n = 0; n < 5; n++)
- printf("%s\t", vl->members & (0x80 >> n) ? (vl->tag & (0x80 >> n) ? "\033[93mT\033[0m" : "\033[92mU\033[0m") : "\033[91m-\033[0m", (unsigned int) vl->members);
+ printf("%s\t", vl->members & (0x80 >> n) ? (vl->tag & (0x80 >> n) ? "\033[93mT\033[0m" : "\033[92mU\033[0m") : "\033[91m-\033[0m" /*, (unsigned int) vl->members*/);
printf("\n");
vl = vl->next;
}
m = atoi(argv[3]);
- if (m < 1 | m > 5) {
+ if ((m < 1) | (m > 5)) {
printf("Invalid Port ID\n");
return;
}
m = atoi(argv[3]);
- if (m < 1 | m > 5) {
+ if ((m < 1) | (m > 5)) {
printf("Invalid Port ID\n");
return;
}
+#define _BSD_SOURCE
+
#include <arpa/inet.h>
#include <sys/socket.h>
#include <stdlib.h>
int recvBroadcast(char * data) {
- struct sockaddr_in sa_in;
- int sa_len = sizeof(sa_in);
+ struct sockaddr sa_in;
+ socklen_t sa_len = sizeof(sa_in);
struct timeval tout;
tout.tv_sec = 0;
tout.tv_usec = 500000;
int s = select(sock + 1, &fds, NULL, NULL, &tout);
if (s <= 0)
return -1;
- return recvfrom(sock, data, PACKET_BUFFER, 0,(struct sockaddr * )&sa_in, &sa_len);
+ return recvfrom(sock, data, PACKET_BUFFER, 0, &sa_in, &sa_len);
}
int recvBroadcast_tout(char * data) {
struct sockaddr_in sa_in;
- int sa_len = sizeof(sa_in);
+ socklen_t sa_len = sizeof(sa_in);
struct timeval tout;
tout.tv_sec = 5;
tout.tv_usec = 0;
unsigned char * myMac;
+int sendBroadcast(char *data, unsigned int len);
+int recvBroadcast(char * data);
+int recvBroadcast_tout(char * data);
+
#define PACKET_BUFFER 2500