-
Notifications
You must be signed in to change notification settings - Fork 36
Merged
Changes from all commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
077c330
Refactored message parser and message generator. All tests pass. Bega…
868cb51
Updated tests for the broadcast flag.
5a767f1
Added DHCP options for REQUEST to _generate_dhcp_message.
e0f17a2
Added IP collision detection via ARP request.
b740d14
Added all state machine states.
16def1d
Removed IP collision detection, AF_PACKET not support in CP sockets. …
861c30a
Refactored dummy data, added freezegun to opt_reqs, added some tests.
5435203
Added some tests. Changed _BUFF reset in _generate_dhcp_message to a …
b6afd52
Removed unused releasing state. Added doc string to DHCP.
9bfe09d
Added more tests.
f5ab202
Merge branch 'adafruit:main' into new_dhcp_state_machine
BiffoBear 08ed3d7
Added tests for helper methods.
fa07b95
Added tests for _handle_dhcp_message
e8f7fe8
Added tests for _handle_dhcp_message
6cb5a50
Added more tests for _handle_dhcp_message function.
152a2f8
Refactored fixtures to make tests more readable.
2888d04
Finished tests for _handle_dhcp_message
f28030e
Finished tests for _dhcp_state_machine
eb351df
Refactored _handle_dhcp_message for readability.
1723d68
Added some comments to explain tests.
c0cc539
Implemented a DHCP packet receiver that only relies on standard socke…
3f85df9
Refactored the FSM to use _receive_dhcp_response instead of socket.so…
688854e
Added ip_in_use() to WIZNET5K to allow DHCP to send an ARP and confir…
ab72630
Added debugging messages to wiznet5k_dhcp.
ebe63b0
Moved _ip_in_use to DHCP and refactored to use a UDP call as W5500 ha…
8d00f52
Moved back to WIZNET5K (final location) and renamed to _ip_address_in…
37b5e03
Refactored DHCP._socket_set to _dhcp_connection_setup and removed soc…
29fc1c8
Refactored DHCP to remove all socket.socket calls.
08345f3
Fixed _dhcp_connection_setup.
0a8eb0f
Fixed sending date.
53176d8
Moved sending message outside receiving loop.
fce4a56
Fixed DHCP resend timing to match DHCP standard.
8bd5bbd
Refactored to use a for loop in _handle_dhcp_message and local variab…
1e03545
Refactored to remove _prepare_and_set_next_state
eb536c0
Refactored to processing message states into a single function - _pro…
9bec64e
Wrote tests for _handle_dhcp_message
29aae43
Completed tests for DHCP helper methods.
24f1d4f
Refactored _handle_DHCP to return 0, a message type or raise a ValueE…
dd1548e
Added tests for _process_messaging_states.
052f037
Deleted obsolete tests for FSM
43b35e3
Added a hexdump to _debugging_message
bbc9887
Added debugging messages
85f8f76
Fine tuned debugging messages and fixed a bug the prevented a command…
9aa49ea
Fixed a bug where the server port was not set. Improved message gener…
4829ec7
Really fixed the server port bug.
b983145
Pause to integrate changes from other pull requests.
db86eb8
Resolved conflicts from recent merges to main.
836bb29
Updated tests to match changes merged in from main.
e6d3ea3
Updated tests to match changes merged in from main.
1792b81
Fixed a glitch in the docstrings that caused Sphinx to fail.
9121bbb
Moved debug_msg() to __init__.py so that all modules can access it.
9a27612
Refactored wiznet5k.py to use debug_msg.
fe302da
DHCP client makes a new connection.
56d2ad0
Restored stashed changes.
c68c293
Merge in changes from main.
05ba882
Refactored DHCP to store IP addresses as byte objects instead of tuples.
9a68fd4
Refactored DHCP to only accept a MAC address as a bytes object.
fa52aab
Removed _DEFAULT_LEASE_TIME.
9ec6b16
Updated tests to remove _DEFAULT_LEASE_TIME.
53d2cfa
Removed unused response_timeout arg from DHCP and tests.
7ad6ed6
Removed DHCP timeout from WIZNET5K call.
a3c71f9
Refactored mac_address to return a bytes object and added error check…
468d802
Removed spurious print statements.
1f286bf
Added a gc.collect to end of FSM.
d2a808c
Improved hexdump for debug_msg function.
08baf1c
Replaced %S with .format in hexdump.
8bc470e
Tidied some doc-strings.
a89bd7f
Added code to assign the ifconfig data to WIZNET5K and to use self._r…
94e7ad3
Added a return to FSM for when renewing fails.
29727c3
Refactored self._renew to None, "renew" or "rebind" to control conten…
895a0e0
Refactored self._lease_time to self._lease.
0fd0fa2
Changed self._sock.recv() back to self._sock.recv(512) in wiznet5k_dn…
793e93f
Moved debug_msg() from init.py to adafruit_wiznet5k_debug.py.
5ea607a
Convert DNS server IP address to dot-quad string before calling socke…
aa30f2e
Updated to latest version of socket.py.
63bf8f7
Merge branch 'main' into new_dhcp_state_machine
FoamyGuy 06c2ea1
fix constant name
FoamyGuy 9bbbc80
Merged in updates from main.
549ca5b
Merge remote-tracking branch 'origin/new_dhcp_state_machine' into new…
82277ca
Increased buffer to 512 bytes due to long DHCP response. Fixed timeou…
fafe6e8
Fixed bug where timeout was calculated as 2 x time.monotonic + n sec…
da2a88a
Added debug text that confirms DHCP releases socket.
df4efb2
Fixed potential infinite loop in WIZNET5K.socket_close.
4002d57
Converted read_sncr and read_snsr results to int so that they can act…
1e373e4
Added a reset to w5500 chip detection.
cc48f9b
Updated with latest changes to origin/main
ffb5e32
Fixed explicit soft reset for w5500.
9231943
Future proofed w5500 initialisation.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,124 @@ | ||
# SPDX-FileCopyrightText: 2022 Martin Stephens | ||
# | ||
# SPDX-License-Identifier: MIT | ||
"""Data for use in test_dhcp_helper_files.py""" | ||
|
||
|
||
def _pad_message(message_section: bytearray, target_length: int) -> bytearray: | ||
"""Pad the message with 0x00.""" | ||
return message_section + bytearray(b"\00" * (target_length - len(message_section))) | ||
|
||
|
||
def _build_message(message_body: bytearray, message_options: bytearray) -> bytearray: | ||
"""Assemble the padded message and body to make a 318 byte packet. The 'header' | ||
section must be 236 bytes and the entire message must be 318 bytes.""" | ||
dhcp_message = _pad_message(message_body, 236) + _pad_message(message_options, 276) | ||
assert len(dhcp_message) == 512 | ||
return dhcp_message | ||
|
||
|
||
# Data for testing send data. | ||
# DHCP DISCOVER messages. | ||
# Default settings (DISCOVER, broadcast=False, default hostname, renew=False) | ||
message = bytearray( | ||
b"\x01\x01\x06\x00o\xff\xff\xff\x00\x17\x00\x00\x00\x00\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x05\x06\x07" | ||
b"\x08\t\x00\x00\x00\x00\x00\x00\x00\x00" | ||
) | ||
options = bytearray( | ||
b"c\x82Sc5\x01\x01\x0c\x12WIZnet040506070809=\x07\x01" | ||
b"\x04\x05\x06\x07\x08\t7\x03\x01\x03\x063\x04\x00v\xa7\x00\xff" | ||
) | ||
DHCP_SEND_01 = _build_message(message, options) | ||
|
||
message = bytearray( | ||
b"\x01\x01\x06\x00o\xff\xff\xff\x00\x17\x00\x00\x00\x00\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x05\x06\x07" | ||
b"\x08\t" | ||
) | ||
options = bytearray( | ||
b"c\x82Sc5\x01\x01\x0c\x12WIZnet040506070809=\x07\x01" | ||
b"\x04\x05\x06\x07\x08\t7\x03\x01\x03\x063\x04\x00v\xa7\x00\xff" | ||
) | ||
DHCP_SEND_02 = _build_message(message, options) | ||
|
||
message = bytearray( | ||
b"\x01\x01\x06\x00o\xff\xff\xff\x00#\x80\x00\xc0\xa8\x03\x04" | ||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18#.9DO" | ||
) | ||
options = bytearray( | ||
b"c\x82Sc5\x01\x01\x0c\x04bert=\x07\x01\x18#.9DO7" | ||
b"\x03\x01\x03\x063\x04\x00v\xa7\x00\xff" | ||
) | ||
DHCP_SEND_03 = _build_message(message, options) | ||
|
||
message = bytearray( | ||
b"\x01\x01\x06\x00o\xff\xff\xff\x00#\x80\x00\x00\x00\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xffa$e*c" | ||
) | ||
options = bytearray( | ||
b"c\x82Sc5\x01\x01\x0c\x05clash=\x07\x01\xffa$e*c7" | ||
b"\x03\x01\x03\x063\x04\x00v\xa7\x00\xff" | ||
) | ||
DHCP_SEND_04 = _build_message(message, options) | ||
|
||
# DHCP REQUEST messages. | ||
message = bytearray( | ||
b"\x01\x01\x06\x00o\xff\xff\xff\x00\x10\x80\x00\x00\x00\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xffa$e*c" | ||
) | ||
|
||
options = bytearray( | ||
b"c\x82Sc5\x01\x03\x0c\nhelicopter=\x07\x01\xffa$e*c7" | ||
b"\x03\x01\x03\x063\x04\x00v\xa7\x002\x04\n\n\n+6\x04\x91B-\x16\xff" | ||
) | ||
DHCP_SEND_05 = _build_message(message, options) | ||
|
||
message = bytearray( | ||
b"\x01\x01\x06\x00o\xff\xff\xff\x00H\x80\x00\x00\x00\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00K?\xa6\x04" | ||
b"\xc8e" | ||
) | ||
|
||
options = bytearray( | ||
b"c\x82Sc5\x01\x03\x0c\x12WIZnet4B3FA604C865=\x07\x01K?\xa6" | ||
b"\x04\xc8e7\x03\x01\x03\x063\x04\x00v\xa7\x002\x04def\x046" | ||
b"\x04\xf5\xa6\x05\x0b\xff" | ||
) | ||
DHCP_SEND_06 = _build_message(message, options) | ||
|
||
# Data to test response parser. | ||
# Basic case, no extra fields, one each of router and DNS. | ||
message = bytearray( | ||
b"\x02\x00\x00\x00\x7f\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xc0" | ||
b"\xa8\x05\x16\x00\x00\x00\x00\x00\x00\x00\x00\x01\x03\x05\x07\t\x0b" | ||
) | ||
|
||
options = bytearray( | ||
b"c\x82Sc5\x01\x02\x01\x04\xc0\xa8\x06\x026\x04\xeao\xde" | ||
b"{3\x04\x00\x01\x01\x00\x03\x04yy\x04\x05\x06\x04\x05\x06" | ||
b'\x07\x08:\x04\x00""\x00;\x04\x0033\x00\xff' | ||
) | ||
GOOD_DATA_01 = _build_message(message, options) | ||
|
||
# Complex case, extra field, 2 routers and 2 DNS servers. | ||
message = bytearray( | ||
b"\x02\x00\x00\x004Vx\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x12$@\n\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x01" | ||
) | ||
options = bytearray( | ||
b"c\x82Sc5\x01\x05<\x05\x01\x02\x03\x04\x05\x01\x04\n\x0b" | ||
b"\x07\xde6\x04zN\x91\x03\x03\x08\n\x0b\x0e\x0f\xff\x00" | ||
b"\xff\x00\x06\x08\x13\x11\x0b\x07****3\x04\x00\x00=;:\x04" | ||
b"\x00\x0e\x17@;\x04\x02\x92]\xde\xff" | ||
) | ||
GOOD_DATA_02 = _build_message(message, options) | ||
|
||
|
||
# | ||
message = bytearray( | ||
b"\x02\x00\x00\x00\xff\xff\xff\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x12$@\n\x00\x00" | ||
b"\x00\x00\x00\x00\x00\x00\x01" | ||
) | ||
options = bytearray(b"c\x82Sc") | ||
BAD_DATA = _build_message(message, options) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New dhcp state machine #95
< 10000 div class="gh-header-actions mt-0 mb-3 mb-md-2 ml-1 flex-md-order-1 flex-shrink-0 d-flex flex-items-center gap-1">New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account