forked from Neirth/FreeNOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented USB incoming bulk transfers and SMSC95xx ethernet packet …
…receiving. Added the netrecv program to receive packets from a libnet device and dump its contents. Modified the USBDevice implementation to actually get the full configuration descriptor with interface and endpoint descriptors appended. Added check for vendor and product id of SMSC95xx in the USBHub (temporary).
- Loading branch information
1 parent
3b10413
commit 58d6671
Showing
13 changed files
with
487 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "NetReceive.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
NetReceive app(argc, argv); | ||
return app.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <FreeNOS/System.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <ARP.h> | ||
#include <Ethernet.h> | ||
#include <MemoryBlock.h> | ||
#include "NetReceive.h" | ||
|
||
// | ||
// Send manual formatted network packets: | ||
// | ||
// $ netsend smsc --arp --dest=192.168.1.123 | ||
// | ||
// Receive and dump network packets: | ||
// | ||
// $ netrecv smsc | ||
// | ||
// Change device parameters: | ||
// | ||
// $ devctl smsc ip_address=192.168.1.2 ether_address=00:11:22:33:44:55 | ||
// $ devctl serial0 baudrate=9600 | ||
// | ||
// Show device status and statistics: | ||
// | ||
// $ devstat smsc | ||
// $ devstat serial0 | ||
// | ||
|
||
NetReceive::NetReceive(int argc, char **argv) | ||
: POSIXApplication(argc, argv) | ||
{ | ||
m_socket = 0; | ||
|
||
m_parser.setDescription("receive network packets"); | ||
m_parser.registerPositional("DEVICE", "device name of network adapter"); | ||
m_parser.registerPositional("ARGS", "optional key=value arguments", 0); | ||
m_parser.registerFlag('a', "arp", "receive ARP packet(s)"); | ||
} | ||
|
||
NetReceive::~NetReceive() | ||
{ | ||
} | ||
|
||
NetReceive::Result NetReceive::initialize() | ||
{ | ||
DEBUG(""); | ||
|
||
for (HashIterator<String, Argument *> it(m_arguments.getFlags()); | ||
it.hasCurrent(); it++) | ||
{ | ||
printf("key = '%s' value = '%s'\n", | ||
*it.key(), it.current()->getName()); | ||
} | ||
|
||
for (Size i = 0; i < m_arguments.getPositionals().count(); i++) | ||
{ | ||
printf("pos[%d]: %s = %s\n", i, m_arguments.getPositionals()[i]->getName(), | ||
m_arguments.getPositionals()[i]->getValue()); | ||
} | ||
|
||
//const String *dev = m_arguments.get("device"); | ||
//if (dev) | ||
// DEBUG("sending on device: " << **dev); | ||
|
||
IPV4::Address ipAddr = (192 << 24) | (168 << 16) | (1 << 8) | (123); | ||
Ethernet::Address etherAddr; | ||
|
||
receiveArp(); | ||
|
||
return Success; | ||
} | ||
|
||
NetReceive::Result NetReceive::exec() | ||
{ | ||
DEBUG(""); | ||
return Success; | ||
} | ||
|
||
NetReceive::Result NetReceive::receiveArp() | ||
{ | ||
u8 packet[1500];// sizeof(Ethernet::Header) + | ||
// sizeof(ARP::Header) ]; | ||
|
||
while (true) | ||
{ | ||
receivePacket(packet, sizeof(packet)); | ||
|
||
Ethernet::Header *ether = (Ethernet::Header *) packet; | ||
ARP::Header *arp = (ARP::Header *) (ether+1); | ||
|
||
if (be16_to_cpu(ether->type) == Ethernet::ARP) | ||
{ | ||
printf("ARP: hw=%u proto=%u hwlen=%u protolen=%u op=%u\n", | ||
be16_to_cpu(arp->hardwareType), | ||
be16_to_cpu(arp->protocolType), | ||
arp->hardwareLength, | ||
arp->protocolLength, | ||
be16_to_cpu(arp->operation)); | ||
printf("ARP: mac src=%x", arp->etherSource.addr[0]); | ||
|
||
for (int i = 1; i < 6; i++) | ||
printf(":%x", arp->etherSource.addr[i]); | ||
|
||
printf(" mac dest=%x", arp->etherDestination.addr[0]); | ||
for (int i = 1; i < 6; i++) | ||
printf(":%x", arp->etherSource.addr[i]); | ||
|
||
printf("\n"); | ||
|
||
printf("ARP: ip src=%x ip dst=%x\n", be32_to_cpu(arp->ipSource), be32_to_cpu(arp->ipDestination)); | ||
return Success; | ||
} | ||
else | ||
printf("skipped (not ARP, type %x)\n", be16_to_cpu(ether->type)); | ||
} | ||
return Success; | ||
} | ||
|
||
NetReceive::Result NetReceive::receivePacket(u8 *packet, Size size) | ||
{ | ||
|
||
DEBUG(""); | ||
|
||
// Receive on physical device | ||
const char *device = m_arguments.getPositionals()[0]->getValue(); | ||
int fd = open(device, O_RDWR); | ||
int result; | ||
|
||
if (fd < 0) | ||
{ | ||
printf("failed to open device '%s': %s\n", device, strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
printf("receiving on device: %s\n", device); | ||
|
||
if ((result = read(fd, packet, size)) <= 0) | ||
{ | ||
printf("failed to receive packet on device '%s': %s\n", | ||
device, strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
printf("received %d bytes\n", result); | ||
|
||
for (int i = 0; i < result; i++) | ||
printf("%x ", packet[i]); | ||
printf("\n"); | ||
|
||
// Done | ||
return Success; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __BIN_NETRECEIVE_H | ||
#define __BIN_NETRECEIVE_H | ||
|
||
#include <IPV4.h> | ||
#include <Ethernet.h> | ||
#include <POSIXApplication.h> | ||
|
||
/** | ||
* Network receive application. | ||
*/ | ||
class NetReceive : public POSIXApplication | ||
{ | ||
public: | ||
|
||
/** | ||
* Class constructor. | ||
*/ | ||
NetReceive(int argc, char **argv); | ||
|
||
/** | ||
* Class destructor. | ||
*/ | ||
virtual ~NetReceive(); | ||
|
||
/** | ||
* Initialize the application. | ||
*/ | ||
virtual Result initialize(); | ||
|
||
/** | ||
* Execute the application event loop. | ||
*/ | ||
virtual Result exec(); | ||
|
||
private: | ||
|
||
Result receiveArp(); | ||
Result receivePacket(u8 *packet, Size size); | ||
|
||
/** Socket */ | ||
int m_socket; | ||
}; | ||
|
||
#endif /* __BIN_NETRECEIVE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (C) 2010 Niek Linnenbank | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
Import('build_env') | ||
|
||
env = build_env.Clone() | ||
env.UseLibraries([ 'libposix', 'liballoc', 'libstd', 'libexec', 'libarch', 'libnet', 'libipc' ]) | ||
env.UseServers(['core']) | ||
env.TargetProgram('netrecv', Glob('*.cpp'), env['bin']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.