Browse Source

TFTP API changed.

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
0780ecf1b6
1 changed files with 26 additions and 16 deletions
  1. 26
    16
      src/core/pxe_export.c

+ 26
- 16
src/core/pxe_export.c View File

760
  * Status: working
760
  * Status: working
761
  */
761
  */
762
 PXENV_EXIT_t pxenv_tftp_open ( t_PXENV_TFTP_OPEN *tftp_open ) {
762
 PXENV_EXIT_t pxenv_tftp_open ( t_PXENV_TFTP_OPEN *tftp_open ) {
763
+	struct sockaddr_in tftp_server;
763
 	struct tftpreq_info_t request;
764
 	struct tftpreq_info_t request;
764
 	struct tftpblk_info_t block;
765
 	struct tftpblk_info_t block;
765
 
766
 
766
 	DBG ( "PXENV_TFTP_OPEN" );
767
 	DBG ( "PXENV_TFTP_OPEN" );
767
 	ENSURE_READY ( tftp_open );
768
 	ENSURE_READY ( tftp_open );
768
 
769
 
769
-	/* Change server address if different */
770
-	if ( tftp_open->ServerIPAddress && 
771
-	     tftp_open->ServerIPAddress!=arptable[ARP_SERVER].ipaddr.s_addr ) {
772
-		memset(arptable[ARP_SERVER].node, 0, ETH_ALEN ); /* kill arp */
773
-		arptable[ARP_SERVER].ipaddr.s_addr=tftp_open->ServerIPAddress;
774
-	}
775
-	/* Ignore gateway address; we can route properly */
776
-	/* Fill in request structure */
777
-	request.name = tftp_open->FileName;
778
-	request.port = ntohs(tftp_open->TFTPPort);
770
+	/* Set server address and port */
771
+	tftp_server.sin_addr.s_addr = tftp_open->ServerIPAddress
772
+		? tftp_open->ServerIPAddress
773
+		: arptable[ARP_SERVER].ipaddr.s_addr;
774
+	tftp_server.sin_port = ntohs ( tftp_open->TFTPPort );
779
 #ifdef WORK_AROUND_BPBATCH_BUG        
775
 #ifdef WORK_AROUND_BPBATCH_BUG        
780
 	/* Force use of port 69; BpBatch tries to use port 4 for some         
776
 	/* Force use of port 69; BpBatch tries to use port 4 for some         
781
 	* bizarre reason.         */        
777
 	* bizarre reason.         */        
782
-	request.port = TFTP_PORT;
778
+	tftp_server.sin_port = TFTP_PORT;
783
 #endif
779
 #endif
780
+	/* Ignore gateway address; we can route properly */
781
+	/* Fill in request structure */
782
+	request.server = &tftp_server;
783
+	request.name = tftp_open->FileName;
784
 	request.blksize = tftp_open->PacketSize;
784
 	request.blksize = tftp_open->PacketSize;
785
 	DBG ( " %@:%d/%s (%d)", tftp_open->ServerIPAddress,
785
 	DBG ( " %@:%d/%s (%d)", tftp_open->ServerIPAddress,
786
-	      request.port, request.name, request.blksize );
786
+	      tftp_open->TFTPPort, request.name, request.blksize );
787
 	if ( !request.blksize ) request.blksize = TFTP_DEFAULTSIZE_PACKET;
787
 	if ( !request.blksize ) request.blksize = TFTP_DEFAULTSIZE_PACKET;
788
 	/* Make request and get first packet */
788
 	/* Make request and get first packet */
789
 	if ( !tftp_block ( &request, &block ) ) {
789
 	if ( !tftp_block ( &request, &block ) ) {
853
  * Status: working
853
  * Status: working
854
  */
854
  */
855
 
855
 
856
-int pxe_tftp_read_block ( unsigned char *data, unsigned int block __unused, unsigned int len, int eof ) {
856
+int pxe_tftp_read_block ( unsigned char *data, unsigned int block __unused,
857
+			  unsigned int len, int eof ) {
857
 	if ( pxe_stack->readfile.buffer ) {
858
 	if ( pxe_stack->readfile.buffer ) {
858
 		if ( pxe_stack->readfile.offset + len >=
859
 		if ( pxe_stack->readfile.offset + len >=
859
 		     pxe_stack->readfile.bufferlen ) return -1;
860
 		     pxe_stack->readfile.bufferlen ) return -1;
865
 }
866
 }
866
 
867
 
867
 PXENV_EXIT_t pxenv_tftp_read_file ( t_PXENV_TFTP_READ_FILE *tftp_read_file ) {
868
 PXENV_EXIT_t pxenv_tftp_read_file ( t_PXENV_TFTP_READ_FILE *tftp_read_file ) {
869
+	struct sockaddr_in tftp_server;
868
 	int rc;
870
 	int rc;
869
 
871
 
870
 	DBG ( "PXENV_TFTP_READ_FILE %s to [%x,%x)", tftp_read_file->FileName,
872
 	DBG ( "PXENV_TFTP_READ_FILE %s to [%x,%x)", tftp_read_file->FileName,
871
-	      tftp_read_file->Buffer, tftp_read_file->Buffer + tftp_read_file->BufferSize );
873
+	      tftp_read_file->Buffer,
874
+	      tftp_read_file->Buffer + tftp_read_file->BufferSize );
872
 	ENSURE_READY ( tftp_read_file );
875
 	ENSURE_READY ( tftp_read_file );
873
 
876
 
874
 	/* inserted by Klaus Wittemeier */
877
 	/* inserted by Klaus Wittemeier */
877
 	memcpy(KERNEL_BUF, tftp_read_file->FileName, sizeof(KERNEL_BUF));
880
 	memcpy(KERNEL_BUF, tftp_read_file->FileName, sizeof(KERNEL_BUF));
878
 	/* end of insertion */
881
 	/* end of insertion */
879
 
882
 
883
+	/* Set server address and port */
884
+	tftp_server.sin_addr.s_addr = tftp_read_file->ServerIPAddress
885
+		? tftp_read_file->ServerIPAddress
886
+		: arptable[ARP_SERVER].ipaddr.s_addr;
887
+	tftp_server.sin_port = ntohs ( tftp_read_file->TFTPSrvPort );
888
+
880
 	pxe_stack->readfile.buffer = phys_to_virt ( tftp_read_file->Buffer );
889
 	pxe_stack->readfile.buffer = phys_to_virt ( tftp_read_file->Buffer );
881
 	pxe_stack->readfile.bufferlen = tftp_read_file->BufferSize;
890
 	pxe_stack->readfile.bufferlen = tftp_read_file->BufferSize;
882
 	pxe_stack->readfile.offset = 0;
891
 	pxe_stack->readfile.offset = 0;
883
 
892
 
884
-	rc = tftp ( tftp_read_file->FileName, pxe_tftp_read_block );
893
+	rc = tftp ( NULL, &tftp_server, tftp_read_file->FileName,
894
+		    pxe_tftp_read_block );
885
 	if ( rc ) {
895
 	if ( rc ) {
886
 		tftp_read_file->Status = PXENV_STATUS_FAILURE;
896
 		tftp_read_file->Status = PXENV_STATUS_FAILURE;
887
 		return PXENV_EXIT_FAILURE;
897
 		return PXENV_EXIT_FAILURE;
906
 	pxe_stack->readfile.bufferlen = 0;
916
 	pxe_stack->readfile.bufferlen = 0;
907
 	pxe_stack->readfile.offset = 0;
917
 	pxe_stack->readfile.offset = 0;
908
 
918
 
909
-	rc = tftp ( tftp_get_fsize->FileName, pxe_tftp_read_block );
919
+#warning "Rewrite pxenv_tftp_get_fsize, please"
910
 	if ( rc ) {
920
 	if ( rc ) {
911
 		tftp_get_fsize->FileSize = 0;
921
 		tftp_get_fsize->FileSize = 0;
912
 		tftp_get_fsize->Status = PXENV_STATUS_FAILURE;
922
 		tftp_get_fsize->Status = PXENV_STATUS_FAILURE;

Loading…
Cancel
Save