; generated by Component: ARM Compiler 5.05 update 2 (build 169) Tool: ArmCC [4d0f38]
; commandline ArmCC [--c99 --list --split_sections --debug -c --asm --interleave -o..\..\..\..\build\demo\mico-fire_f429\obj_rvmdk\httpd.o --asm_dir=..\..\..\..\Build\demo\MICO-Fire_F429\list_RVMDK\ --list_dir=..\..\..\..\Build\demo\MICO-Fire_F429\list_RVMDK\ --depend=..\..\..\..\build\demo\mico-fire_f429\obj_rvmdk\httpd.d --cpu=Cortex-M4.fp --apcs=interwork -O0 --diag_suppress=9931,1,1293 -I..\..\..\..\Board\fire_F429 -I..\..\..\..\Demos\fire\ov2640 -I..\..\..\..\include -I..\..\..\..\libraries\utilities -I..\..\..\..\libraries\utilities\json_c -I..\..\..\..\MICO\core -I..\..\..\..\MICO\security -I..\..\..\..\MICO\system -I..\..\..\..\MICO\system\command_console -I..\..\..\..\Platform\include -I..\..\..\..\Platform\Cortex-M4 -I..\..\..\..\Platform\Cortex-M4\CMSIS -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals\Libraries\STM32F4xx_StdPeriph_Driver\inc -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals\Libraries -I..\..\..\..\Platform\MCU\STM32F4xx\wlan_bus_driver -I..\..\..\..\Platform\Drivers\spi_flash -I..\..\..\..\Platform\Drivers -I..\..\..\..\libraries\daemons\homekit_server -I..\..\..\..\libraries\daemons\http_server -I..\..\..\..\Platform\Drivers\malloc -I..\..\..\..\Platform\Drivers\SDRAM -I..\..\..\..\Platform\Drivers\ov5640 -IG:\GIT_OSC\STM32_develop\F429-V2\develop\6-WIFI\STM32-WiFi\3.wifi_ov5640\Projects\STM32F429\demo\RVMDK\RTE -IC:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include -IC:\Keil_v5\ARM\CMSIS\Include -IC:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0 -D__UVISION_VERSION=515 -DSTM32F429xx -DUSE_STDPERIPH_DRIVER -DDEBUG -DHSE_VALUE=25000000 -DOV5640 --omf_browse=..\..\..\..\build\demo\mico-fire_f429\obj_rvmdk\httpd.crf ..\..\..\..\libraries\daemons\http_server\httpd.c]
                          THUMB

                          AREA ||i.httpd_accept_client_socket||, CODE, READONLY, ALIGN=2

                  httpd_accept_client_socket PROC
;;;224    
;;;225    static int  httpd_accept_client_socket(const fd_set *active_readfds)
000000  b530              PUSH     {r4,r5,lr}
;;;226    {
000002  b089              SUB      sp,sp,#0x24
000004  4604              MOV      r4,r0
;;;227      int main_sockfd = -1;
000006  f04f35ff          MOV      r5,#0xffffffff
;;;228      struct sockaddr_t addr_from;
;;;229      int addr_from_len;
;;;230      
;;;231      if (FD_ISSET(http_sockfd, active_readfds)) {
00000a  4828              LDR      r0,|L1.172|
00000c  6800              LDR      r0,[r0,#0]  ; http_sockfd
00000e  0940              LSRS     r0,r0,#5
000010  f8540020          LDR      r0,[r4,r0,LSL #2]
000014  4925              LDR      r1,|L1.172|
000016  7809              LDRB     r1,[r1,#0]  ; http_sockfd
000018  f001021f          AND      r2,r1,#0x1f
00001c  2101              MOVS     r1,#1
00001e  4091              LSLS     r1,r1,r2
000020  4008              ANDS     r0,r0,r1
000022  b120              CBZ      r0,|L1.46|
;;;232        main_sockfd = http_sockfd;
000024  4821              LDR      r0,|L1.172|
000026  6805              LDR      r5,[r0,#0]  ; http_sockfd
;;;233        https_active  = FALSE;
000028  2000              MOVS     r0,#0
00002a  4921              LDR      r1,|L1.176|
00002c  7008              STRB     r0,[r1,#0]
                  |L1.46|
;;;234      }
;;;235      
;;;236      addr_from_len = sizeof(addr_from);
00002e  2014              MOVS     r0,#0x14
000030  9003              STR      r0,[sp,#0xc]
;;;237      
;;;238      client_sockfd = accept(main_sockfd, &addr_from, &addr_from_len);
000032  aa03              ADD      r2,sp,#0xc
000034  a904              ADD      r1,sp,#0x10
000036  4628              MOV      r0,r5
000038  f7fffffe          BL       accept
00003c  491d              LDR      r1,|L1.180|
00003e  6008              STR      r0,[r1,#0]  ; client_sockfd
;;;239      if (client_sockfd < 0) {
000040  4608              MOV      r0,r1
000042  6800              LDR      r0,[r0,#0]  ; client_sockfd
000044  2800              CMP      r0,#0
000046  da03              BGE      |L1.80|
;;;240        httpd_d("net_accept client socket failed %d.", client_sockfd);
;;;241        return -kInProgressErr;
000048  f04f30ff          MOV      r0,#0xffffffff
                  |L1.76|
;;;242      }
;;;243      
;;;244      /*
;;;245      * Enable TCP Keep-alive for accepted client connection
;;;246      *  -- By enabling this feature TCP sends probe packet if there is
;;;247      *  inactivity over connection for specfied interval
;;;248      *  -- If there is no response to probe packet for specified retries
;;;249      *  then connection is closed with RST packet to peer end
;;;250      *  -- Ref: http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/
;;;251      *
;;;252      * We are doing this as we have single threaded web server with
;;;253      * synchronous (blocking) API usage like send, recv and they might get
;;;254      * blocked due to un-availability of peer end, causing web server to
;;;255      * be in-responsive forever.
;;;256      */
;;;257      int optval = true;
;;;258      if (setsockopt(client_sockfd, SOL_SOCKET, 0x0008, &optval, sizeof(optval)) == -1) {
;;;259        httpd_d("Unsupported option SO_KEEPALIVE: %d", net_get_sock_error(client_sockfd));
;;;260      }
;;;261      
;;;262      /* TCP Keep-alive idle/inactivity timeout is 10 seconds */
;;;263      optval = 10;
;;;264      if (setsockopt(client_sockfd, IPPROTO_TCP, 0x03, &optval, sizeof(optval)) == -1) {
;;;265        httpd_d("Unsupported option TCP_KEEPIDLE: %d", net_get_sock_error(client_sockfd));
;;;266      }
;;;267      
;;;268      /* TCP Keep-alive retry count is 5 */
;;;269      optval = 5;
;;;270      if (setsockopt(client_sockfd, IPPROTO_TCP, 0x05, &optval, sizeof(optval)) == -1) {
;;;271        httpd_d("Unsupported option TCP_KEEPCNT: %d", net_get_sock_error(client_sockfd));
;;;272      }
;;;273      
;;;274      /* TCP Keep-alive retry interval (in case no response for probe
;;;275      * packet) is 1 second.
;;;276      */
;;;277      optval = 1;
;;;278      if (setsockopt(client_sockfd, IPPROTO_TCP, 0x04, &optval, sizeof(optval)) == -1) {
;;;279        httpd_d("Unsupported option TCP_KEEPINTVL: %d", net_get_sock_error(client_sockfd));
;;;280      }
;;;281      
;;;282      httpd_d("connecting %d to %d.", client_sockfd, addr_from.s_port);
;;;283      
;;;284      return kNoErr;
;;;285    }
00004c  b009              ADD      sp,sp,#0x24
00004e  bd30              POP      {r4,r5,pc}
                  |L1.80|
000050  2001              MOVS     r0,#1                 ;257
000052  9002              STR      r0,[sp,#8]            ;257
000054  2004              MOVS     r0,#4                 ;258
000056  ab02              ADD      r3,sp,#8              ;258
000058  2208              MOVS     r2,#8                 ;258
00005a  2101              MOVS     r1,#1                 ;258
00005c  9000              STR      r0,[sp,#0]            ;258
00005e  4815              LDR      r0,|L1.180|
000060  6800              LDR      r0,[r0,#0]            ;258  ; client_sockfd
000062  f7fffffe          BL       setsockopt
000066  200a              MOVS     r0,#0xa               ;263
000068  9002              STR      r0,[sp,#8]            ;263
00006a  2004              MOVS     r0,#4                 ;264
00006c  ab02              ADD      r3,sp,#8              ;264
00006e  2203              MOVS     r2,#3                 ;264
000070  2106              MOVS     r1,#6                 ;264
000072  9000              STR      r0,[sp,#0]            ;264
000074  480f              LDR      r0,|L1.180|
000076  6800              LDR      r0,[r0,#0]            ;264  ; client_sockfd
000078  f7fffffe          BL       setsockopt
00007c  2005              MOVS     r0,#5                 ;269
00007e  9002              STR      r0,[sp,#8]            ;269
000080  2004              MOVS     r0,#4                 ;270
000082  ab02              ADD      r3,sp,#8              ;270
000084  2205              MOVS     r2,#5                 ;270
000086  2106              MOVS     r1,#6                 ;270
000088  9000              STR      r0,[sp,#0]            ;270
00008a  480a              LDR      r0,|L1.180|
00008c  6800              LDR      r0,[r0,#0]            ;270  ; client_sockfd
00008e  f7fffffe          BL       setsockopt
000092  2001              MOVS     r0,#1                 ;277
000094  9002              STR      r0,[sp,#8]            ;277
000096  2004              MOVS     r0,#4                 ;278
000098  ab02              ADD      r3,sp,#8              ;278
00009a  4602              MOV      r2,r0                 ;278
00009c  2106              MOVS     r1,#6                 ;278
00009e  9000              STR      r0,[sp,#0]            ;278
0000a0  4804              LDR      r0,|L1.180|
0000a2  6800              LDR      r0,[r0,#0]            ;278  ; client_sockfd
0000a4  f7fffffe          BL       setsockopt
0000a8  2000              MOVS     r0,#0                 ;284
0000aa  e7cf              B        |L1.76|
;;;286    
                          ENDP

                  |L1.172|
                          DCD      http_sockfd
                  |L1.176|
                          DCD      https_active
                  |L1.180|
                          DCD      client_sockfd

                          AREA ||i.httpd_close_sockets||, CODE, READONLY, ALIGN=2

                  httpd_close_sockets PROC
;;;99     
;;;100    static int httpd_close_sockets()
000000  b570              PUSH     {r4-r6,lr}
;;;101    {
;;;102      int ret, status = kNoErr;
000002  2500              MOVS     r5,#0
;;;103      
;;;104      if (http_sockfd != -1) {
000004  4810              LDR      r0,|L2.72|
000006  6800              LDR      r0,[r0,#0]  ; http_sockfd
000008  1c40              ADDS     r0,r0,#1
00000a  b150              CBZ      r0,|L2.34|
;;;105        ret = close(http_sockfd);
00000c  480e              LDR      r0,|L2.72|
00000e  6800              LDR      r0,[r0,#0]  ; http_sockfd
000010  f7fffffe          BL       close
000014  4604              MOV      r4,r0
;;;106        if (ret != 0) {
000016  b104              CBZ      r4,|L2.26|
;;;107          httpd_d("failed to close http socket: %d", net_get_sock_error(http_sockfd));
;;;108          status = -kInProgressErr;
000018  1e6d              SUBS     r5,r5,#1
                  |L2.26|
;;;109        }
;;;110      http_sockfd = -1;
00001a  f04f30ff          MOV      r0,#0xffffffff
00001e  490a              LDR      r1,|L2.72|
000020  6008              STR      r0,[r1,#0]  ; http_sockfd
                  |L2.34|
;;;111      }
;;;112      
;;;113      if (client_sockfd != -1) {
000022  480a              LDR      r0,|L2.76|
000024  6800              LDR      r0,[r0,#0]  ; client_sockfd
000026  1c40              ADDS     r0,r0,#1
000028  b158              CBZ      r0,|L2.66|
;;;114        ret = close(client_sockfd);
00002a  4808              LDR      r0,|L2.76|
00002c  6800              LDR      r0,[r0,#0]  ; client_sockfd
00002e  f7fffffe          BL       close
000032  4604              MOV      r4,r0
;;;115        if (ret != 0) {
000034  b10c              CBZ      r4,|L2.58|
;;;116          httpd_d("Failed to close client socket: %d", net_get_sock_error(client_sockfd));
;;;117          status = -kInProgressErr;
000036  f04f35ff          MOV      r5,#0xffffffff
                  |L2.58|
;;;118        }
;;;119        client_sockfd = -1;
00003a  f04f30ff          MOV      r0,#0xffffffff
00003e  4903              LDR      r1,|L2.76|
000040  6008              STR      r0,[r1,#0]  ; client_sockfd
                  |L2.66|
;;;120      }
;;;121      
;;;122      return status;
000042  4628              MOV      r0,r5
;;;123    }
000044  bd70              POP      {r4-r6,pc}
;;;124    
                          ENDP

000046  0000              DCW      0x0000
                  |L2.72|
                          DCD      http_sockfd
                  |L2.76|
                          DCD      client_sockfd

                          AREA ||i.httpd_handle_client_connection||, CODE, READONLY, ALIGN=2

                  httpd_handle_client_connection PROC
;;;286    
;;;287    static void httpd_handle_client_connection(const fd_set *active_readfds)
000000  b5f8              PUSH     {r3-r7,lr}
;;;288    {
000002  4606              MOV      r6,r0
;;;289      int activefds_cnt, status;
;;;290      fd_set readfds;
;;;291      
;;;292      if (httpd_stop_req) {
000004  4835              LDR      r0,|L3.220|
000006  7800              LDRB     r0,[r0,#0]  ; httpd_stop_req
000008  b120              CBZ      r0,|L3.20|
;;;293        httpd_d("HTTPD stop request received");
;;;294        httpd_stop_req = FALSE;
00000a  2000              MOVS     r0,#0
00000c  4933              LDR      r1,|L3.220|
00000e  7008              STRB     r0,[r1,#0]
;;;295        httpd_suspend_thread(false);
000010  f7fffffe          BL       httpd_suspend_thread
                  |L3.20|
;;;296      }
;;;297      
;;;298      status = httpd_accept_client_socket(active_readfds);
000014  4630              MOV      r0,r6
000016  f7fffffe          BL       httpd_accept_client_socket
00001a  4604              MOV      r4,r0
;;;299      if (status != kNoErr)
00001c  b104              CBZ      r4,|L3.32|
                  |L3.30|
;;;300        return;
;;;301      
;;;302      httpd_d("Client socket accepted: %d", client_sockfd);
;;;303      FD_ZERO(&readfds);
;;;304      FD_SET(client_sockfd, &readfds);
;;;305      
;;;306      while (1) {
;;;307        if (httpd_stop_req) {
;;;308          httpd_d("HTTPD stop request received");
;;;309          httpd_stop_req = FALSE;
;;;310          httpd_suspend_thread(false);
;;;311        }
;;;312        
;;;313        httpd_d("Waiting on client socket");
;;;314        activefds_cnt = httpd_select(client_sockfd, &readfds, NULL, HTTPD_CLIENT_SOCK_TIMEOUT);
;;;315        
;;;316        if (httpd_stop_req) {
;;;317          httpd_d("HTTPD stop request received");
;;;318          httpd_stop_req = FALSE;
;;;319          httpd_suspend_thread(false);
;;;320        }
;;;321        
;;;322        if (activefds_cnt == HTTPD_TIMEOUT_EVENT) {
;;;323          /* Timeout has occured */
;;;324          httpd_d("Client socket timeout occurred. " "Force closing socket");
;;;325    
;;;326          status = close(client_sockfd);
;;;327          if (status != kNoErr) {
;;;328            status = net_get_sock_error(client_sockfd);
;;;329            httpd_d("Failed to close socket %d", status);
;;;330            httpd_suspend_thread(true);
;;;331          }
;;;332          
;;;333          client_sockfd = -1;
;;;334          break;
;;;335        }
;;;336        
;;;337        httpd_d("Handling %d", client_sockfd);
;;;338        /* Note:
;;;339        * Connection will be handled with call to
;;;340        * httpd_handle_message twice, first for
;;;341        * handling request (kNoErr) and second
;;;342        * time as there is no more data to receive
;;;343        * (client closed connection) and hence
;;;344        * will return with status HTTPD_DONE
;;;345        * closing socket.
;;;346        */
;;;347        /* FIXME: remove this memset if all is working well */
;;;348        /* memset(&httpd_message_in[0], 0, sizeof(httpd_message_in)); */
;;;349        status = httpd_handle_message(client_sockfd);
;;;350        if (status == kNoErr) {
;;;351          /* The handlers are expected more data on the
;;;352          socket */
;;;353          continue;
;;;354        }
;;;355        
;;;356        /* Either there was some error or everything went well */
;;;357        httpd_d("Close socket %d.  %s: %d", client_sockfd, status == HTTPD_DONE ? "Handler done" : "Handler failed", status);
;;;358        
;;;359        status = close(client_sockfd);
;;;360        if (status != kNoErr) {
;;;361          status = net_get_sock_error(client_sockfd);
;;;362          httpd_d("Failed to close socket %d", status);
;;;363          httpd_suspend_thread(true);
;;;364        }
;;;365        client_sockfd = -1;
;;;366        
;;;367        break;
;;;368      }
;;;369    }
00001e  bdf8              POP      {r3-r7,pc}
                  |L3.32|
000020  2000              MOVS     r0,#0                 ;303
000022  9000              STR      r0,[sp,#0]            ;303
000024  482e              LDR      r0,|L3.224|
000026  6800              LDR      r0,[r0,#0]            ;304  ; client_sockfd
000028  0940              LSRS     r0,r0,#5              ;304
00002a  f85d0020          LDR      r0,[sp,r0,LSL #2]     ;304
00002e  492c              LDR      r1,|L3.224|
000030  7809              LDRB     r1,[r1,#0]            ;304  ; client_sockfd
000032  f001021f          AND      r2,r1,#0x1f           ;304
000036  2101              MOVS     r1,#1                 ;304
000038  4091              LSLS     r1,r1,r2              ;304
00003a  4308              ORRS     r0,r0,r1              ;304
00003c  4928              LDR      r1,|L3.224|
00003e  6809              LDR      r1,[r1,#0]            ;304  ; client_sockfd
000040  0949              LSRS     r1,r1,#5              ;304
000042  f84d0021          STR      r0,[sp,r1,LSL #2]     ;304
000046  e045              B        |L3.212|
                  |L3.72|
000048  4824              LDR      r0,|L3.220|
00004a  7800              LDRB     r0,[r0,#0]            ;307  ; httpd_stop_req
00004c  b120              CBZ      r0,|L3.88|
00004e  2000              MOVS     r0,#0                 ;309
000050  4922              LDR      r1,|L3.220|
000052  7008              STRB     r0,[r1,#0]            ;309
000054  f7fffffe          BL       httpd_suspend_thread
                  |L3.88|
000058  230a              MOVS     r3,#0xa               ;314
00005a  2200              MOVS     r2,#0                 ;314
00005c  4669              MOV      r1,sp                 ;314
00005e  4820              LDR      r0,|L3.224|
000060  6800              LDR      r0,[r0,#0]            ;314  ; client_sockfd
000062  f7fffffe          BL       httpd_select
000066  4605              MOV      r5,r0                 ;314
000068  481c              LDR      r0,|L3.220|
00006a  7800              LDRB     r0,[r0,#0]            ;316  ; httpd_stop_req
00006c  b120              CBZ      r0,|L3.120|
00006e  2000              MOVS     r0,#0                 ;318
000070  491a              LDR      r1,|L3.220|
000072  7008              STRB     r0,[r1,#0]            ;318
000074  f7fffffe          BL       httpd_suspend_thread
                  |L3.120|
000078  b995              CBNZ     r5,|L3.160|
00007a  4819              LDR      r0,|L3.224|
00007c  6800              LDR      r0,[r0,#0]            ;326  ; client_sockfd
00007e  f7fffffe          BL       close
000082  4604              MOV      r4,r0                 ;326
000084  b13c              CBZ      r4,|L3.150|
000086  4816              LDR      r0,|L3.224|
000088  6800              LDR      r0,[r0,#0]            ;328  ; client_sockfd
00008a  f7fffffe          BL       net_get_sock_error
00008e  4604              MOV      r4,r0                 ;328
000090  2001              MOVS     r0,#1                 ;330
000092  f7fffffe          BL       httpd_suspend_thread
                  |L3.150|
000096  f04f30ff          MOV      r0,#0xffffffff        ;333
00009a  4911              LDR      r1,|L3.224|
00009c  6008              STR      r0,[r1,#0]            ;333  ; client_sockfd
00009e  e01a              B        |L3.214|
                  |L3.160|
0000a0  480f              LDR      r0,|L3.224|
0000a2  6800              LDR      r0,[r0,#0]            ;349  ; client_sockfd
0000a4  f7fffffe          BL       httpd_handle_message
0000a8  4604              MOV      r4,r0                 ;349
0000aa  b904              CBNZ     r4,|L3.174|
0000ac  e012              B        |L3.212|
                  |L3.174|
0000ae  480c              LDR      r0,|L3.224|
0000b0  6800              LDR      r0,[r0,#0]            ;359  ; client_sockfd
0000b2  f7fffffe          BL       close
0000b6  4604              MOV      r4,r0                 ;359
0000b8  b13c              CBZ      r4,|L3.202|
0000ba  4809              LDR      r0,|L3.224|
0000bc  6800              LDR      r0,[r0,#0]            ;361  ; client_sockfd
0000be  f7fffffe          BL       net_get_sock_error
0000c2  4604              MOV      r4,r0                 ;361
0000c4  2001              MOVS     r0,#1                 ;363
0000c6  f7fffffe          BL       httpd_suspend_thread
                  |L3.202|
0000ca  f04f30ff          MOV      r0,#0xffffffff        ;365
0000ce  4904              LDR      r1,|L3.224|
0000d0  6008              STR      r0,[r1,#0]            ;365  ; client_sockfd
0000d2  e000              B        |L3.214|
                  |L3.212|
0000d4  e7b8              B        |L3.72|
                  |L3.214|
0000d6  bf00              NOP                            ;334
0000d8  bf00              NOP      
0000da  e7a0              B        |L3.30|
;;;370    
                          ENDP

                  |L3.220|
                          DCD      httpd_stop_req
                  |L3.224|
                          DCD      client_sockfd

                          AREA ||i.httpd_init||, CODE, READONLY, ALIGN=2

                  httpd_init PROC
;;;553    /* This pairs with httpd_shutdown() */
;;;554    int httpd_init()
000000  b510              PUSH     {r4,lr}
;;;555    {
;;;556      int status;
;;;557      
;;;558      if (httpd_state != HTTPD_INACTIVE)
000002  480e              LDR      r0,|L4.60|
000004  7800              LDRB     r0,[r0,#0]  ; httpd_state
000006  b108              CBZ      r0,|L4.12|
;;;559        return kNoErr;
000008  2000              MOVS     r0,#0
                  |L4.10|
;;;560      
;;;561      httpd_d("Initializing");
;;;562      
;;;563      client_sockfd = -1;
;;;564      http_sockfd  = -1;
;;;565      
;;;566      status = httpd_wsgi_init();
;;;567      if (status != kNoErr) {
;;;568        httpd_d("Failed to initialize WSGI!");
;;;569        return status;
;;;570      }
;;;571      
;;;572      status = httpd_ssi_init();
;;;573      if (status != kNoErr) {
;;;574        httpd_d("Failed to initialize SSI!");
;;;575        return status;
;;;576      }
;;;577      
;;;578      httpd_state = HTTPD_INIT_DONE;
;;;579      
;;;580      return kNoErr;
;;;581    }
00000a  bd10              POP      {r4,pc}
                  |L4.12|
00000c  f04f30ff          MOV      r0,#0xffffffff        ;563
000010  490b              LDR      r1,|L4.64|
000012  6008              STR      r0,[r1,#0]            ;563  ; client_sockfd
000014  490b              LDR      r1,|L4.68|
000016  6008              STR      r0,[r1,#0]            ;564  ; http_sockfd
000018  f7fffffe          BL       httpd_wsgi_init
00001c  4604              MOV      r4,r0                 ;566
00001e  b10c              CBZ      r4,|L4.36|
000020  4620              MOV      r0,r4                 ;569
000022  e7f2              B        |L4.10|
                  |L4.36|
000024  f7fffffe          BL       httpd_ssi_init
000028  4604              MOV      r4,r0                 ;572
00002a  b10c              CBZ      r4,|L4.48|
00002c  4620              MOV      r0,r4                 ;575
00002e  e7ec              B        |L4.10|
                  |L4.48|
000030  2001              MOVS     r0,#1                 ;578
000032  4902              LDR      r1,|L4.60|
000034  7008              STRB     r0,[r1,#0]            ;578
000036  2000              MOVS     r0,#0                 ;580
000038  e7e7              B        |L4.10|
;;;582    
                          ENDP

00003a  0000              DCW      0x0000
                  |L4.60|
                          DCD      httpd_state
                  |L4.64|
                          DCD      client_sockfd
                  |L4.68|
                          DCD      http_sockfd

                          AREA ||i.httpd_is_https_active||, CODE, READONLY, ALIGN=2

                  httpd_is_https_active PROC
;;;89     
;;;90     bool httpd_is_https_active()
000000  4801              LDR      r0,|L5.8|
;;;91     {
;;;92       return https_active;
000002  7800              LDRB     r0,[r0,#0]  ; https_active
;;;93     }
000004  4770              BX       lr
;;;94     
                          ENDP

000006  0000              DCW      0x0000
                  |L5.8|
                          DCD      https_active

                          AREA ||i.httpd_is_running||, CODE, READONLY, ALIGN=2

                  httpd_is_running PROC
;;;503    
;;;504    int httpd_is_running(void)
000000  4803              LDR      r0,|L6.16|
;;;505    {
;;;506      return (httpd_state == HTTPD_THREAD_RUNNING);
000002  7800              LDRB     r0,[r0,#0]  ; httpd_state
000004  2802              CMP      r0,#2
000006  d101              BNE      |L6.12|
000008  2001              MOVS     r0,#1
                  |L6.10|
;;;507    }
00000a  4770              BX       lr
                  |L6.12|
00000c  2000              MOVS     r0,#0                 ;506
00000e  e7fc              B        |L6.10|
;;;508    
                          ENDP

                  |L6.16|
                          DCD      httpd_state

                          AREA ||i.httpd_main||, CODE, READONLY, ALIGN=2

                  httpd_main PROC
;;;370    
;;;371    static void httpd_main(void *arg)
000000  b51c              PUSH     {r2-r4,lr}
;;;372    {
;;;373      int status, max_sockfd = -1;
000002  f04f35ff          MOV      r5,#0xffffffff
;;;374      fd_set readfds, active_readfds;
;;;375      
;;;376      status = httpd_setup_main_sockets();
000006  f7fffffe          BL       httpd_setup_main_sockets
00000a  4604              MOV      r4,r0
;;;377      if (status != kNoErr)
00000c  b114              CBZ      r4,|L7.20|
;;;378        httpd_suspend_thread(true);
00000e  2001              MOVS     r0,#1
000010  f7fffffe          BL       httpd_suspend_thread
                  |L7.20|
;;;379      
;;;380      FD_ZERO(&readfds);
000014  2000              MOVS     r0,#0
000016  9001              STR      r0,[sp,#4]
;;;381      
;;;382      FD_SET(http_sockfd, &readfds);
000018  4810              LDR      r0,|L7.92|
00001a  6800              LDR      r0,[r0,#0]  ; http_sockfd
00001c  0940              LSRS     r0,r0,#5
00001e  a901              ADD      r1,sp,#4
000020  f8510020          LDR      r0,[r1,r0,LSL #2]
000024  490d              LDR      r1,|L7.92|
000026  7809              LDRB     r1,[r1,#0]  ; http_sockfd
000028  f001021f          AND      r2,r1,#0x1f
00002c  2101              MOVS     r1,#1
00002e  4091              LSLS     r1,r1,r2
000030  4308              ORRS     r0,r0,r1
000032  490a              LDR      r1,|L7.92|
000034  6809              LDR      r1,[r1,#0]  ; http_sockfd
000036  0949              LSRS     r1,r1,#5
000038  aa01              ADD      r2,sp,#4
00003a  f8420021          STR      r0,[r2,r1,LSL #2]
;;;383      max_sockfd = http_sockfd;
00003e  4807              LDR      r0,|L7.92|
000040  6805              LDR      r5,[r0,#0]  ; http_sockfd
;;;384      
;;;385      while (1) {
000042  e009              B        |L7.88|
                  |L7.68|
;;;386        httpd_d("Waiting on main socket");
;;;387        httpd_select(max_sockfd, &readfds, &active_readfds, -1);
000044  f04f33ff          MOV      r3,#0xffffffff
000048  466a              MOV      r2,sp
00004a  a901              ADD      r1,sp,#4
00004c  4628              MOV      r0,r5
00004e  f7fffffe          BL       httpd_select
;;;388        httpd_handle_client_connection(&active_readfds);
000052  4668              MOV      r0,sp
000054  f7fffffe          BL       httpd_handle_client_connection
                  |L7.88|
000058  e7f4              B        |L7.68|
;;;389      }
;;;390      
;;;391      /*
;;;392      * Thread will never come here. The functions called from the above
;;;393      * infinite loop will cleanly shutdown this thread when situation
;;;394      * demands so.
;;;395      */
;;;396    }
;;;397    
                          ENDP

00005a  0000              DCW      0x0000
                  |L7.92|
                          DCD      http_sockfd

                          AREA ||i.httpd_select||, CODE, READONLY, ALIGN=2

                  httpd_select PROC
;;;185    
;;;186    static int httpd_select(int max_sock, const fd_set *readfds,
000000  e92d41ff          PUSH     {r0-r8,lr}
;;;187                            fd_set *active_readfds, int timeout_secs)
;;;188    {
000004  4680              MOV      r8,r0
000006  460f              MOV      r7,r1
000008  4616              MOV      r6,r2
00000a  461c              MOV      r4,r3
;;;189      int activefds_cnt;
;;;190      struct timeval_t timeout;
;;;191      
;;;192      fd_set local_readfds;
;;;193      
;;;194      if (timeout_secs >= 0)
00000c  2c00              CMP      r4,#0
00000e  db00              BLT      |L8.18|
;;;195        timeout.tv_sec = timeout_secs;
000010  9402              STR      r4,[sp,#8]
                  |L8.18|
;;;196      timeout.tv_usec = 0;
000012  2000              MOVS     r0,#0
000014  9003              STR      r0,[sp,#0xc]
;;;197      
;;;198      memcpy(&local_readfds, readfds, sizeof(fd_set));
000016  6838              LDR      r0,[r7,#0]
000018  9001              STR      r0,[sp,#4]
;;;199      httpd_d("WAITING for activity");
;;;200      
;;;201      activefds_cnt = select(1, &local_readfds, NULL, NULL, timeout_secs >= 0 ? &timeout : NULL);
00001a  2c00              CMP      r4,#0
00001c  db01              BLT      |L8.34|
00001e  a802              ADD      r0,sp,#8
000020  e000              B        |L8.36|
                  |L8.34|
000022  2000              MOVS     r0,#0
                  |L8.36|
000024  2300              MOVS     r3,#0
000026  461a              MOV      r2,r3
000028  a901              ADD      r1,sp,#4
00002a  9000              STR      r0,[sp,#0]
00002c  2001              MOVS     r0,#1
00002e  f7fffffe          BL       select
000032  4605              MOV      r5,r0
;;;202      if (activefds_cnt < 0) {
000034  2d00              CMP      r5,#0
000036  da02              BGE      |L8.62|
;;;203        httpd_d("Select failed: %d", timeout_secs);
;;;204        httpd_suspend_thread(true);
000038  2001              MOVS     r0,#1
00003a  f7fffffe          BL       httpd_suspend_thread
                  |L8.62|
;;;205      }
;;;206      
;;;207      if (httpd_stop_req) {
00003e  4809              LDR      r0,|L8.100|
000040  7800              LDRB     r0,[r0,#0]  ; httpd_stop_req
000042  b120              CBZ      r0,|L8.78|
;;;208        httpd_d("HTTPD stop request received");
;;;209        httpd_stop_req = FALSE;
000044  2000              MOVS     r0,#0
000046  4907              LDR      r1,|L8.100|
000048  7008              STRB     r0,[r1,#0]
;;;210        httpd_suspend_thread(false);
00004a  f7fffffe          BL       httpd_suspend_thread
                  |L8.78|
;;;211      }
;;;212      
;;;213      if (activefds_cnt) {
00004e  b135              CBZ      r5,|L8.94|
;;;214        /* Update users copy of fd_set only if he wants */
;;;215        if (active_readfds)
000050  b10e              CBZ      r6,|L8.86|
;;;216          memcpy(active_readfds, &local_readfds, sizeof(fd_set));
000052  9801              LDR      r0,[sp,#4]
000054  6030              STR      r0,[r6,#0]
                  |L8.86|
;;;217        return activefds_cnt;
000056  4628              MOV      r0,r5
                  |L8.88|
;;;218      }
;;;219      
;;;220      httpd_d("TIMEOUT");
;;;221      
;;;222      return HTTPD_TIMEOUT_EVENT;
;;;223    }
000058  b004              ADD      sp,sp,#0x10
00005a  e8bd81f0          POP      {r4-r8,pc}
                  |L8.94|
00005e  2000              MOVS     r0,#0                 ;222
000060  e7fa              B        |L8.88|
;;;224    
                          ENDP

000062  0000              DCW      0x0000
                  |L8.100|
                          DCD      httpd_stop_req

                          AREA ||i.httpd_setup_main_sockets||, CODE, READONLY, ALIGN=2

                  httpd_setup_main_sockets PROC
;;;174    
;;;175    static int httpd_setup_main_sockets()
000000  b510              PUSH     {r4,lr}
;;;176    {
;;;177      http_sockfd = httpd_setup_new_socket(HTTP_PORT);
000002  2050              MOVS     r0,#0x50
000004  f7fffffe          BL       httpd_setup_new_socket
000008  4905              LDR      r1,|L9.32|
00000a  6008              STR      r0,[r1,#0]  ; http_sockfd
;;;178      if (http_sockfd < 0) {
00000c  4608              MOV      r0,r1
00000e  6800              LDR      r0,[r0,#0]  ; http_sockfd
000010  2800              CMP      r0,#0
000012  da02              BGE      |L9.26|
;;;179        /* Socket creation failed */
;;;180        return http_sockfd;
000014  4608              MOV      r0,r1
000016  6800              LDR      r0,[r0,#0]  ; http_sockfd
                  |L9.24|
;;;181      }
;;;182      
;;;183      return kNoErr;
;;;184    }
000018  bd10              POP      {r4,pc}
                  |L9.26|
00001a  2000              MOVS     r0,#0                 ;183
00001c  e7fc              B        |L9.24|
;;;185    
                          ENDP

00001e  0000              DCW      0x0000
                  |L9.32|
                          DCD      http_sockfd

                          AREA ||i.httpd_setup_new_socket||, CODE, READONLY, ALIGN=1

                  httpd_setup_new_socket PROC
;;;136    
;;;137    static int httpd_setup_new_socket(int port)
000000  b570              PUSH     {r4-r6,lr}
;;;138    {
000002  b088              SUB      sp,sp,#0x20
000004  4605              MOV      r5,r0
;;;139      int one = 1;
000006  2001              MOVS     r0,#1
000008  9007              STR      r0,[sp,#0x1c]
;;;140      int status, sockfd;
;;;141      struct sockaddr_t addr_listen;
;;;142      
;;;143      /* create listening TCP socket */
;;;144      sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
00000a  2206              MOVS     r2,#6
00000c  2101              MOVS     r1,#1
00000e  2002              MOVS     r0,#2
000010  f7fffffe          BL       socket
000014  4606              MOV      r6,r0
;;;145      if (sockfd < 0) {
000016  2e00              CMP      r6,#0
000018  da06              BGE      |L10.40|
;;;146        status = net_get_sock_error(sockfd);
00001a  4630              MOV      r0,r6
00001c  f7fffffe          BL       net_get_sock_error
000020  4604              MOV      r4,r0
;;;147        httpd_d("Socket creation failed: Port: %d Status: %d", port, status);
;;;148        return status;
000022  4620              MOV      r0,r4
                  |L10.36|
;;;149      }
;;;150      
;;;151      setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
;;;152    
;;;153      addr_listen.s_ip = INADDR_ANY;
;;;154      addr_listen.s_port = port;
;;;155      
;;;156      /* bind insocket */
;;;157      status = bind(sockfd, &addr_listen, sizeof(addr_listen));
;;;158      if (status < 0) {
;;;159        status = net_get_sock_error(sockfd);
;;;160        httpd_d("Failed to bind socket on port: %d Status: %d", status, port);
;;;161        return status;
;;;162      }
;;;163      
;;;164      status = listen(sockfd, HTTPD_MAX_BACKLOG_CONN);
;;;165      if (status < 0) {
;;;166        status = net_get_sock_error(sockfd);
;;;167        httpd_d("Failed to listen on port %d: %d.", port, status);
;;;168        return status;
;;;169      }
;;;170      
;;;171      httpd_d("Listening on port %d.", port);
;;;172      return sockfd;
;;;173    }
000024  b008              ADD      sp,sp,#0x20
000026  bd70              POP      {r4-r6,pc}
                  |L10.40|
000028  2004              MOVS     r0,#4                 ;151
00002a  ab07              ADD      r3,sp,#0x1c           ;151
00002c  2202              MOVS     r2,#2                 ;151
00002e  2101              MOVS     r1,#1                 ;151
000030  9000              STR      r0,[sp,#0]            ;151
000032  4630              MOV      r0,r6                 ;151
000034  f7fffffe          BL       setsockopt
000038  2000              MOVS     r0,#0                 ;153
00003a  9003              STR      r0,[sp,#0xc]          ;153
00003c  b2a8              UXTH     r0,r5                 ;154
00003e  f8ad000a          STRH     r0,[sp,#0xa]          ;154
000042  2214              MOVS     r2,#0x14              ;157
000044  a902              ADD      r1,sp,#8              ;157
000046  4630              MOV      r0,r6                 ;157
000048  f7fffffe          BL       bind
00004c  4604              MOV      r4,r0                 ;157
00004e  2c00              CMP      r4,#0                 ;158
000050  da05              BGE      |L10.94|
000052  4630              MOV      r0,r6                 ;159
000054  f7fffffe          BL       net_get_sock_error
000058  4604              MOV      r4,r0                 ;159
00005a  4620              MOV      r0,r4                 ;161
00005c  e7e2              B        |L10.36|
                  |L10.94|
00005e  2105              MOVS     r1,#5                 ;164
000060  4630              MOV      r0,r6                 ;164
000062  f7fffffe          BL       listen
000066  4604              MOV      r4,r0                 ;164
000068  2c00              CMP      r4,#0                 ;165
00006a  da05              BGE      |L10.120|
00006c  4630              MOV      r0,r6                 ;166
00006e  f7fffffe          BL       net_get_sock_error
000072  4604              MOV      r4,r0                 ;166
000074  4620              MOV      r0,r4                 ;168
000076  e7d5              B        |L10.36|
                  |L10.120|
000078  4630              MOV      r0,r6                 ;172
00007a  e7d3              B        |L10.36|
;;;174    
                          ENDP


                          AREA ||i.httpd_shutdown||, CODE, READONLY, ALIGN=2

                  httpd_shutdown PROC
;;;537    /* This pairs with httpd_init() */
;;;538    int httpd_shutdown(void)
000000  b510              PUSH     {r4,lr}
;;;539    {
;;;540      int ret;
;;;541      
;;;542      httpd_d("Shutting down.");
;;;543      
;;;544      ret = httpd_thread_cleanup();
000002  f7fffffe          BL       httpd_thread_cleanup
000006  4604              MOV      r4,r0
;;;545      if (ret != kNoErr)
;;;546        httpd_d("Thread cleanup failed");
;;;547      
;;;548      httpd_state = HTTPD_INACTIVE;
000008  2000              MOVS     r0,#0
00000a  4902              LDR      r1,|L11.20|
00000c  7008              STRB     r0,[r1,#0]
;;;549      
;;;550      return ret;
00000e  4620              MOV      r0,r4
;;;551    }
000010  bd10              POP      {r4,pc}
;;;552    
                          ENDP

000012  0000              DCW      0x0000
                  |L11.20|
                          DCD      httpd_state

                          AREA ||i.httpd_signal_and_wait_for_halt||, CODE, READONLY, ALIGN=2

                  httpd_signal_and_wait_for_halt PROC
;;;444    
;;;445    static int httpd_signal_and_wait_for_halt()
000000  b5f8              PUSH     {r3-r7,lr}
;;;446    {
;;;447      const int total_wait_time_ms = 1000 * 20;	/* 20 seconds */
000002  f6446620          MOV      r6,#0x4e20
;;;448      const int check_interval_ms = 100;	/* 100 ms */
000006  2764              MOVS     r7,#0x64
;;;449      
;;;450      int num_iterations = total_wait_time_ms / check_interval_ms;
000008  25c8              MOVS     r5,#0xc8
;;;451      
;;;452      httpd_d("Sent stop request");
;;;453      httpd_stop_req = TRUE;
00000a  2001              MOVS     r0,#1
00000c  4911              LDR      r1,|L12.84|
00000e  7008              STRB     r0,[r1,#0]
;;;454      
;;;455      /* Do a dummy local connect to wakeup the httpd thread */
;;;456      int sockfd;
;;;457      int rv = tcp_local_connect(&sockfd);
000010  4668              MOV      r0,sp
000012  f7fffffe          BL       tcp_local_connect
000016  4604              MOV      r4,r0
;;;458      if (rv != kNoErr)
000018  b10c              CBZ      r4,|L12.30|
;;;459        return rv;
00001a  4620              MOV      r0,r4
                  |L12.28|
;;;460      
;;;461      while (httpd_state != HTTPD_THREAD_SUSPENDED && num_iterations--) {
;;;462        mico_thread_msleep(check_interval_ms);
;;;463      }
;;;464      
;;;465      close(sockfd);
;;;466      if (httpd_state == HTTPD_THREAD_SUSPENDED)
;;;467        return kNoErr;
;;;468      
;;;469      httpd_d("Timed out waiting for httpd to stop. " "Force closed temporary socket");
;;;470      
;;;471      httpd_stop_req = FALSE;
;;;472      return -kInProgressErr;
;;;473    }
00001c  bdf8              POP      {r3-r7,pc}
                  |L12.30|
00001e  e002              B        |L12.38|
                  |L12.32|
000020  2064              MOVS     r0,#0x64              ;462
000022  f7fffffe          BL       msleep
                  |L12.38|
000026  480c              LDR      r0,|L12.88|
000028  7800              LDRB     r0,[r0,#0]            ;461  ; httpd_state
00002a  2803              CMP      r0,#3                 ;461
00002c  d003              BEQ      |L12.54|
00002e  0028              MOVS     r0,r5                 ;461
000030  f1a50501          SUB      r5,r5,#1              ;461
000034  d1f4              BNE      |L12.32|
                  |L12.54|
000036  9800              LDR      r0,[sp,#0]            ;465
000038  f7fffffe          BL       close
00003c  4806              LDR      r0,|L12.88|
00003e  7800              LDRB     r0,[r0,#0]            ;466  ; httpd_state
000040  2803              CMP      r0,#3                 ;466
000042  d101              BNE      |L12.72|
000044  2000              MOVS     r0,#0                 ;467
000046  e7e9              B        |L12.28|
                  |L12.72|
000048  2000              MOVS     r0,#0                 ;471
00004a  4902              LDR      r1,|L12.84|
00004c  7008              STRB     r0,[r1,#0]            ;471
00004e  1e40              SUBS     r0,r0,#1              ;472
000050  e7e4              B        |L12.28|
;;;474    
                          ENDP

000052  0000              DCW      0x0000
                  |L12.84|
                          DCD      httpd_stop_req
                  |L12.88|
                          DCD      httpd_state

                          AREA ||i.httpd_start||, CODE, READONLY, ALIGN=2

                  httpd_start PROC
;;;509    /* This pairs with httpd_stop() */
;;;510    int httpd_start(void)
000000  b51c              PUSH     {r2-r4,lr}
;;;511    {
;;;512      int status;
;;;513      
;;;514      if (httpd_state != HTTPD_INIT_DONE) {
000002  480d              LDR      r0,|L13.56|
000004  7800              LDRB     r0,[r0,#0]  ; httpd_state
000006  2801              CMP      r0,#1
000008  d001              BEQ      |L13.14|
;;;515        httpd_d("Already started");
;;;516        return kNoErr;
00000a  2000              MOVS     r0,#0
                  |L13.12|
;;;517      }
;;;518      
;;;519      status = mico_rtos_create_thread(&httpd_main_thread, MICO_APPLICATION_PRIORITY, "httpd", 
;;;520                                       httpd_main, http_server_thread_stack_size,  NULL);
;;;521    
;;;522      if (status != kNoErr) {
;;;523        httpd_d("Failed to create httpd thread: %d", status);
;;;524        return -kInProgressErr;
;;;525      }
;;;526      
;;;527      httpd_state = HTTPD_THREAD_RUNNING;
;;;528      return kNoErr;
;;;529    }
00000c  bd1c              POP      {r2-r4,pc}
                  |L13.14|
00000e  2000              MOVS     r0,#0                 ;519
000010  f44f5100          MOV      r1,#0x2000            ;519
000014  4b09              LDR      r3,|L13.60|
000016  a20a              ADR      r2,|L13.64|
000018  e9cd1000          STRD     r1,r0,[sp,#0]         ;519
00001c  2107              MOVS     r1,#7                 ;519
00001e  480a              LDR      r0,|L13.72|
000020  f7fffffe          BL       mico_rtos_create_thread
000024  4604              MOV      r4,r0                 ;519
000026  b114              CBZ      r4,|L13.46|
000028  f04f30ff          MOV      r0,#0xffffffff        ;524
00002c  e7ee              B        |L13.12|
                  |L13.46|
00002e  2002              MOVS     r0,#2                 ;527
000030  4901              LDR      r1,|L13.56|
000032  7008              STRB     r0,[r1,#0]            ;527
000034  2000              MOVS     r0,#0                 ;528
000036  e7e9              B        |L13.12|
;;;530    
                          ENDP

                  |L13.56|
                          DCD      httpd_state
                  |L13.60|
                          DCD      httpd_main
                  |L13.64|
000040  68747470          DCB      "httpd",0
000044  6400    
000046  00                DCB      0
000047  00                DCB      0
                  |L13.72|
                          DCD      httpd_main_thread

                          AREA ||i.httpd_stop||, CODE, READONLY, ALIGN=1

                  httpd_stop PROC
;;;531    /* This pairs with httpd_start() */
;;;532    int httpd_stop(void)
000000  b510              PUSH     {r4,lr}
;;;533    {
;;;534      return httpd_thread_cleanup();
000002  f7fffffe          BL       httpd_thread_cleanup
;;;535    }
000006  bd10              POP      {r4,pc}
;;;536    
                          ENDP


                          AREA ||i.httpd_suspend_thread||, CODE, READONLY, ALIGN=2

                  httpd_suspend_thread PROC
;;;124    
;;;125    static void httpd_suspend_thread(bool warn)
000000  b510              PUSH     {r4,lr}
;;;126    {
000002  4604              MOV      r4,r0
;;;127      if (warn) {
;;;128        httpd_d("Suspending thread");
;;;129      } else {
;;;130        httpd_d("Suspending thread");
;;;131      }
;;;132      httpd_close_sockets();
000004  f7fffffe          BL       httpd_close_sockets
;;;133      httpd_state = HTTPD_THREAD_SUSPENDED;
000008  2003              MOVS     r0,#3
00000a  4903              LDR      r1,|L15.24|
00000c  7008              STRB     r0,[r1,#0]
;;;134      mico_rtos_suspend_thread(NULL);
00000e  2000              MOVS     r0,#0
000010  f7fffffe          BL       mico_rtos_suspend_thread
;;;135    }
000014  bd10              POP      {r4,pc}
;;;136    
                          ENDP

000016  0000              DCW      0x0000
                  |L15.24|
                          DCD      httpd_state

                          AREA ||i.httpd_thread_cleanup||, CODE, READONLY, ALIGN=2

                  httpd_thread_cleanup PROC
;;;474    
;;;475    static int httpd_thread_cleanup(void)
000000  b510              PUSH     {r4,lr}
;;;476    {
;;;477      int status = kNoErr;
000002  2400              MOVS     r4,#0
;;;478      
;;;479      switch (httpd_state) {
000004  480f              LDR      r0,|L16.68|
000006  7800              LDRB     r0,[r0,#0]  ; httpd_state
000008  2801              CMP      r0,#1
00000a  d004              BEQ      |L16.22|
00000c  2802              CMP      r0,#2
00000e  d003              BEQ      |L16.24|
000010  2803              CMP      r0,#3
000012  d110              BNE      |L16.54|
000014  e004              B        |L16.32|
                  |L16.22|
;;;480      case HTTPD_INIT_DONE:
;;;481        /*
;;;482        * We have no threads, no sockets to close.
;;;483        */
;;;484        break;
000016  e011              B        |L16.60|
                  |L16.24|
;;;485      case HTTPD_THREAD_RUNNING:
;;;486        status = httpd_signal_and_wait_for_halt();
000018  f7fffffe          BL       httpd_signal_and_wait_for_halt
00001c  4604              MOV      r4,r0
;;;487        if (status != kNoErr)
;;;488          httpd_d("Unable to stop thread. Force killing it.");
;;;489        /* No break here on purpose */
;;;490      case HTTPD_THREAD_SUSPENDED:
00001e  bf00              NOP      
                  |L16.32|
;;;491        status = mico_rtos_delete_thread(&httpd_main_thread);
000020  4809              LDR      r0,|L16.72|
000022  f7fffffe          BL       mico_rtos_delete_thread
000026  4604              MOV      r4,r0
;;;492        if (status != kNoErr)
;;;493          httpd_d("Failed to delete thread.");
;;;494        status = httpd_close_sockets();
000028  f7fffffe          BL       httpd_close_sockets
00002c  4604              MOV      r4,r0
;;;495        httpd_state = HTTPD_INIT_DONE;
00002e  2001              MOVS     r0,#1
000030  4904              LDR      r1,|L16.68|
000032  7008              STRB     r0,[r1,#0]
;;;496        break;
000034  e002              B        |L16.60|
                  |L16.54|
;;;497      default:
;;;498        return -kInProgressErr;
000036  f04f30ff          MOV      r0,#0xffffffff
                  |L16.58|
;;;499      }
;;;500      
;;;501      return status;
;;;502    }
00003a  bd10              POP      {r4,pc}
                  |L16.60|
00003c  bf00              NOP                            ;484
00003e  4620              MOV      r0,r4                 ;501
000040  e7fb              B        |L16.58|
;;;503    
                          ENDP

000042  0000              DCW      0x0000
                  |L16.68|
                          DCD      httpd_state
                  |L16.72|
                          DCD      httpd_main_thread

                          AREA ||i.httpd_use_tls_certificates||, CODE, READONLY, ALIGN=1

                  httpd_use_tls_certificates PROC
;;;582    
;;;583    int httpd_use_tls_certificates(const httpd_tls_certs_t *tls_certs)
000000  4601              MOV      r1,r0
;;;584    {
;;;585    
;;;586      httpd_d("HTTPS is not enabled in server. ");
;;;587      return -kInProgressErr;
000002  f04f30ff          MOV      r0,#0xffffffff
;;;588    }
000006  4770              BX       lr
                          ENDP


                          AREA ||i.net_get_sock_error||, CODE, READONLY, ALIGN=1

                  net_get_sock_error PROC
;;;94     
;;;95     static int net_get_sock_error( int sock)
000000  4601              MOV      r1,r0
;;;96     {
;;;97       return -kInProgressErr;
000002  f04f30ff          MOV      r0,#0xffffffff
;;;98     }
000006  4770              BX       lr
;;;99     
                          ENDP


                          AREA ||i.tcp_local_connect||, CODE, READONLY, ALIGN=2

                  tcp_local_connect PROC
;;;397    
;;;398    static inline int tcp_local_connect(int *sockfd)
000000  b5f0              PUSH     {r4-r7,lr}
;;;399    {
000002  b085              SUB      sp,sp,#0x14
000004  4604              MOV      r4,r0
;;;400      uint16_t port;
;;;401      int retry_cnt = 3;
000006  2703              MOVS     r7,#3
;;;402      
;;;403      httpd_d("Doing local connect for shutting down server\n\r");
;;;404      
;;;405      *sockfd = -1;
000008  1f38              SUBS     r0,r7,#4
00000a  6020              STR      r0,[r4,#0]
;;;406      while (retry_cnt--) {
00000c  e00d              B        |L19.42|
                  |L19.14|
;;;407        *sockfd = socket(AF_INET, SOCK_STREAM, 0);
00000e  2200              MOVS     r2,#0
000010  2101              MOVS     r1,#1
000012  2002              MOVS     r0,#2
000014  f7fffffe          BL       socket
000018  6020              STR      r0,[r4,#0]
;;;408        if (*sockfd >= 0)
00001a  6820              LDR      r0,[r4,#0]
00001c  2800              CMP      r0,#0
00001e  db00              BLT      |L19.34|
;;;409          break;
000020  e007              B        |L19.50|
                  |L19.34|
;;;410        /* Wait some time to allow some sockets to get released */
;;;411        mico_thread_msleep(1000);
000022  f44f707a          MOV      r0,#0x3e8
000026  f7fffffe          BL       msleep
                  |L19.42|
00002a  0038              MOVS     r0,r7                 ;406
00002c  f1a70701          SUB      r7,r7,#1              ;406
000030  d1ed              BNE      |L19.14|
                  |L19.50|
000032  bf00              NOP                            ;409
;;;412      }
;;;413      
;;;414      if (*sockfd < 0) {
000034  6820              LDR      r0,[r4,#0]
000036  2800              CMP      r0,#0
000038  da03              BGE      |L19.66|
;;;415        httpd_d("Unable to create socket to stop server");
;;;416        return -kInProgressErr;
00003a  f04f30ff          MOV      r0,#0xffffffff
                  |L19.62|
;;;417      }
;;;418      
;;;419      port = HTTP_PORT;
;;;420      
;;;421      char *host = "127.0.0.1";
;;;422      struct sockaddr_t addr;
;;;423      memset(&addr, 0, sizeof(struct sockaddr_t));
;;;424      
;;;425      addr.s_port = port;
;;;426      addr.s_ip = inet_addr(host);
;;;427      
;;;428      httpd_d("local connecting ...");
;;;429      if (connect(*sockfd, &addr, sizeof(addr)) != 0) {
;;;430        httpd_d("Server close error. tcp connect failed %s:%d", host, port);
;;;431        close(*sockfd);
;;;432        *sockfd = 0;
;;;433        return -kInProgressErr;
;;;434      }
;;;435      
;;;436      /*
;;;437      * We do not wish to do anything with this connection. Its sole
;;;438      * purpose was to wake the main httpd thread out of sleep.
;;;439      */
;;;440      
;;;441      return kNoErr;
;;;442    }
00003e  b005              ADD      sp,sp,#0x14
000040  bdf0              POP      {r4-r7,pc}
                  |L19.66|
000042  2550              MOVS     r5,#0x50              ;419
000044  a60c              ADR      r6,|L19.120|
000046  2114              MOVS     r1,#0x14              ;423
000048  4668              MOV      r0,sp                 ;423
00004a  f7fffffe          BL       __aeabi_memclr4
00004e  f8ad5002          STRH     r5,[sp,#2]            ;425
000052  4630              MOV      r0,r6                 ;426
000054  f7fffffe          BL       inet_addr
000058  9001              STR      r0,[sp,#4]            ;426
00005a  2214              MOVS     r2,#0x14              ;429
00005c  4669              MOV      r1,sp                 ;429
00005e  6820              LDR      r0,[r4,#0]            ;429
000060  f7fffffe          BL       connect
000064  b130              CBZ      r0,|L19.116|
000066  6820              LDR      r0,[r4,#0]            ;431
000068  f7fffffe          BL       close
00006c  2000              MOVS     r0,#0                 ;432
00006e  6020              STR      r0,[r4,#0]            ;432
000070  1e40              SUBS     r0,r0,#1              ;433
000072  e7e4              B        |L19.62|
                  |L19.116|
000074  2000              MOVS     r0,#0                 ;441
000076  e7e2              B        |L19.62|
;;;443    
                          ENDP

                  |L19.120|
000078  3132372e          DCB      "127.0.0.1",0
00007c  302e302e
000080  3100    
000082  00                DCB      0
000083  00                DCB      0

                          AREA ||.data||, DATA, ALIGN=2

                  httpd_state
000000  00000000          DCB      0x00,0x00,0x00,0x00
                  httpd_main_thread
                          DCD      0x00000000
                  httpd_stop_req
000008  00000000          DCB      0x00,0x00,0x00,0x00
                  http_sockfd
                          DCD      0x00000000
                  client_sockfd
                          DCD      0x00000000
                  https_active
000014  00                DCB      0x00

;*** Start embedded assembler ***

#line 1 "..\\..\\..\\..\\libraries\\daemons\\http_server\\httpd.c"
	AREA ||.rev16_text||, CODE
	THUMB
	EXPORT |__asm___7_httpd_c_76e25adc____REV16|
#line 114 "..\\..\\..\\..\\Platform\\Cortex-M4\\CMSIS\\core_cmInstr.h"
|__asm___7_httpd_c_76e25adc____REV16| PROC
#line 115

 rev16 r0, r0
 bx lr
	ENDP
	AREA ||.revsh_text||, CODE
	THUMB
	EXPORT |__asm___7_httpd_c_76e25adc____REVSH|
#line 128
|__asm___7_httpd_c_76e25adc____REVSH| PROC
#line 129

 revsh r0, r0
 bx lr
	ENDP

;*** End   embedded assembler ***
