{"id":115,"date":"2015-12-29T19:00:45","date_gmt":"2015-12-29T19:00:45","guid":{"rendered":"http:\/\/blogs.nrao.edu\/jmalone\/?p=115"},"modified":"2015-12-29T19:01:10","modified_gmt":"2015-12-29T19:01:10","slug":"fsr-fun-bit-banging-http-post","status":"publish","type":"post","link":"https:\/\/blogs.nrao.edu\/jmalone\/2015\/12\/29\/fsr-fun-bit-banging-http-post\/","title":{"rendered":"FSR fun: Bit-banging HTTP POST"},"content":{"rendered":"<p>So, now that I have the Aurora LXC-200 RPC API figured out, I&#8217;m moving closer to my ultimate goal of having an FSR FLEX-LT use an LXC-200 as an expansion serial port. There&#8217;s just one problem: The FLEX doesn&#8217;t speak HTTP. It has the capability of communicating with IP devices, but just with raw bits &#8211; unlike the WACI, no protocol is implemented in it&#8217;s firmware. Well&#8230;. what&#8217;s a protocol, anyway, but a series of bits on the wire.<\/p>\n<p>So, let&#8217;s come up with the most bare-bones version of an HTTP POST that we can. This technique is no stranger to anyone who&#8217;s ever used telnet to simulate an HTTP connection. We just want to make sure we make ours as stripped down as possible to preserve space in the FLEX&#8217;s memory; the FLEX is a small device compared to the WACI and <em>every command<\/em> we send to one of the LXC ports has to implement this POST inside it&#8217;s IP command. This is&#8230; unfortunate, but &#8211; hey &#8211; desperate times and all that.<\/p>\n<p>We&#8217;ll start by using the ubiquitous &#8216;nc&#8217; to test our series of bits. nc has the option to use &#8216;crlf&#8217; to terminate lines, so that should work for our HTTP POST. We&#8217;ll create a file with our commands in it:<\/p>\n<pre>POST \/rpc\/ HTTP\/1.1\r\nContent-Type: application\/x-www-form-urlencoded\r\nmethod=Serial_Send&amp;param1=1&amp;param2=nc+test&amp;param3=10\r\n<\/pre>\n<p>And tell netcat to send this to our LXC device:<\/p>\n<pre>$ cat lxptest.nc | nc -v -c a.b.c.d 80<\/pre>\n<p>And viola! Our lovely test string &#8220;nc test&#8221; is sent from the serial port. Watching the traffic with Wireshark, it doesn&#8217;t recognize the packets as proper HTTP, but the LXC is forgiving enough to honor the command.<\/p>\n<p>Now, as I mentioned, every FSR command that sends data to an LXC port will need to implement this fake HTTP POST request. The easiest way to do this is to create a custom IP device with a single command &#8220;Serial send&#8221;. This command can be used via &#8220;Send Inline IP&#8230;&#8221; wherever we need it in our FLEX project; just replace the &#8216;param2&#8217; bits with the data you want to send &#8211; properly URL encoded, of course.<\/p>\n<p>Putting this all into an inline IP command looks like:<\/p>\n<p>IP &#8216;Aurora_LXC-200_1_Addr&#8217; INLINE &#8220;POST \/rpc\/ HTTP\/1.1&lt;0D 0A&gt;Content-Type: application\/x-www-form-urlencoded&lt;0D 0A 0D 0A&gt;method=Serial_Send&amp;param1=1&amp;param2=data&amp;param3=10&lt;0D 0A&gt;&#8221;<\/p>\n<p>&#8230;but running this command via a button press on the FLEX results in nothing but an empty TCP connection. The connection is started with a 3-way handshake and then torn down similarly, with no attempt at an HTTP command. *frowny* What&#8217;s going on here? Let&#8217;s change the device IP from the LXC to my desktop, run nc -l on port 8888 and press that button again. Same thing &#8211; an empty connection with no data sent. Let&#8217;s try something simpler. We&#8217;ll change the IP command to just<\/p>\n<p>IP &#8216;Aurora_LXC-200_1_Addr&#8217; INLINE &#8220;Hello world&lt;0d&gt;&#8221;<\/p>\n<p>&#8230;and lo and behold, that works! We get &#8220;Hello world&#8221; spit out from our listening nc. So&#8230;. there&#8217;s something it doesn&#8217;t like about the HTTP data.<\/p>\n<p>#include &lt;swearword.h&gt;<\/p>\n<p>I guess I&#8217;ll have to keep increasing the complexity of the command until I find out what the problem is.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, now that I have the Aurora LXC-200 RPC API figured out, I&#8217;m moving closer to my ultimate goal of having an FSR FLEX-LT use an LXC-200 as an expansion serial port. There&#8217;s just one problem: The FLEX doesn&#8217;t speak &hellip; <a class=\"more-link\" href=\"https:\/\/blogs.nrao.edu\/jmalone\/2015\/12\/29\/fsr-fun-bit-banging-http-post\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry","category-audiovisual"],"_links":{"self":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts\/115"}],"collection":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":6,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":121,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts\/115\/revisions\/121"}],"wp:attachment":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}