#include <minmax.h>
#include <sys/cpu.h>
#include "pxe.h"
-#if 1
-#include "lwip/api.h"
-#include "lwip/dns.h"
-#endif
+#include <lwip/api.h>
+#include <lwip/dns.h>
static uint16_t real_base_mem; /* Amount of DOS memory after freeing */
/* Common receive buffer */
__lowmem char packet_buf[PKTBUF_SIZE] __aligned(16);
+static struct url_open {
+ const char *scheme;
+ void (*open)(struct inode *inode, const char *url);
+} url_table[] = {
+ { NULL, NULL },
+};
+
/*
* Allocate a local UDP port structure and assign it a local port number.
* Return the inode pointer if success, or null if failure
* return the the string address after the ip string
*
*/
-static const char *parse_dotquad(const char *ip_str, uint32_t *res)
+const char *parse_dotquad(const char *ip_str, uint32_t *res)
{
const char *p = ip_str;
uint8_t part = 0;
}
/*
+ * Read a single character from the specified pxe inode.
+ * Very useful for stepping through http streams and
+ * parsing their headers.
+ */
+int pxe_getc(struct inode *inode)
+{
+ struct pxe_pvt_inode *socket = PVT(inode);
+ unsigned char byte;
+
+ while (!socket->tftp_bytesleft) {
+ if (socket->tftp_goteof)
+ return -1;
+
+ socket->fill_buffer(inode);
+ }
+
+ byte = *socket->tftp_dataptr;
+ socket->tftp_bytesleft -= 1;
+ socket->tftp_dataptr += 1;
+
+ return byte;
+}
+
+/*
* Get a fresh packet if the buffer is drained, and we haven't hit
* EOF yet. The buffer should be filled immediately after draining!
*/
if (!inode)
return; /* Allocation failure */
+ if (path_type == PXE_URL) {
+ struct url_open *entry;
+ np = strchr(filename, ':');
+
+ for (entry = url_table; entry->scheme; entry++) {
+ int scheme_len = strlen(entry->scheme);
+ if (scheme_len != (np - filename))
+ continue;
+ if (memcmp(entry->scheme, filename, scheme_len) != 0)
+ continue;
+ entry->open(inode, filename);
+ goto done;
+ }
+ }
+
#if GPXE
if (path_type == PXE_URL) {
if (has_gpxe) {
} __attribute__ ((packed));
struct netconn;
+struct netbuf;
/*
* Our inode private information -- this includes the packet buffer!
*/
struct pxe_pvt_inode {
struct netconn *conn; /* lwip network connection */
+ struct netbuf *buf; /* lwip cached buffer */
uint16_t tftp_localport; /* Local port number (0=not in us)*/
uint16_t tftp_remoteport; /* Remote port number */
uint32_t tftp_remoteip; /* Remote IP address */
bool ip_ok(uint32_t);
int pxe_call(int, void *);
extern __lowmem char packet_buf[PKTBUF_SIZE] __aligned(16);
+const char *parse_dotquad(const char *ip_str, uint32_t *res);
+int pxe_getc(struct inode *inode);
/* dhcp_options.c */
void parse_dhcp(int);