Skip to content
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

Proxy UART Stack Drops RX Packet Length in GET #202

Open
kb1lqd opened this issue May 31, 2017 · 0 comments
Open

Proxy UART Stack Drops RX Packet Length in GET #202

kb1lqd opened this issue May 31, 2017 · 0 comments
Assignees
Labels

Comments

@kb1lqd
Copy link
Contributor

kb1lqd commented May 31, 2017

Summary

Proxy UART stack parses the data, data length, and service port in the layer 4 functions but when placing data into the RX queue for RESTful GET to return the FULL maximum packet is always returned instead of only the received data.

Problem Explanation

The UART stack is a fixed length protocol always transferring 123 bytes of payload information from a packet. Each layer 4 UART packet also contains a data length byte indicating the length of the payload data the exact data placed into the packet can be extracted from the padding.

https://github.com/FaradayRF/Faraday-Software/blob/master/faraday/uart/layer_4_protocol.py#L35
shown below extracts the layer 4 packet and returns it to the calling function.

def parse_packet(datagram):
    #Parse Layer 4 datagram
    parsedpacket = struct.unpack('BB123s', datagram)

    #Return parsed datagram
    return parsedpacket

The calling function in https://github.com/FaradayRF/Faraday-Software/blob/master/faraday/uart/layer_4_service.py#L221

def run(self):
        while(self.enabled):
            #Delay to allow CPU utilization relaxing
            time.sleep(0.001)
            #check for transmit items
            if(self.transmit_datagram_queue_hasitem()):
                tx_datagram = self.transmit_datagram_queue_get()
                self.layer_2_object.POST(tx_datagram)
            #check for receive items
            if self.receive_datagram_queue_hasitem():
                rx_datagram = self.receive_datagram_queue_get()
                try:
                    parsed_l4_packet = layer_4_protocol.parse_packet(rx_datagram)
                    self.receive_service_queue_put(parsed_l4_packet[2], parsed_l4_packet[0])

                except:
                    logger.info('FAILED PARSING' + str(rx_datagram))
                    pass
            #Check uart datalink receive for new datagrams to parse
            self.uart_layer_receive_link()

simply ignores the payload length data parsed and returns the ENTIRE packet.

This is incorrect because ideally DATA IN == DATA OUT of a packetized network layer. Data of 42 bytes long in expects to be returned as 42 bytes output.

The correct fix for this is to change:

self.receive_service_queue_put(parsed_l4_packet[2], parsed_l4_packet[0])

to

self.receive_service_queue_put(parsed_l4_packet[2][0:parsed_l4_packet[1]], parsed_l4_packet[0])

which places only the original data into the proxy queue and removes all padding.

Environment

Software

I'm using an older master but this this is present in the current master as linked.

Hardware

Faraday REV D

Supporting Information

Data is a constant 42 byte packet sent from Faraday firmware, no proxy TX is involved.

Incorrect (Below) shows data returned from proxy randomly returning 42 bytes and 123 bytes (padding included in return).

image

When the data is extracted as described above the correct packet is always returned with NO padding.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants