cc

Dependencies:   ATParser

Revision:
26:70852d26853e
Parent:
25:6b79352bc1fa
Child:
27:0dc1402f42a9
--- a/SPWFSA01.cpp	Mon Jan 02 14:46:40 2017 +0000
+++ b/SPWFSA01.cpp	Fri Jan 13 09:56:54 2017 +0000
@@ -250,7 +250,7 @@
     Timer timer;
     timer.start();
     socket_closed = 0; 
-         
+
     if(!_parser.send("AT+S.SOCKON=%s,%d,%s,ind", addr, port, type))
         {
             debug_if(dbg_on, "SPWF> error opening socket\r\n");
@@ -316,7 +316,6 @@
     _parser.setTimeout(0);
     
      while(_parser.recv("+WIND:%d:", &wind_id)) {
-//        printf("Wind received: %d\n\r", wind_id);
         if (wind_id == 58) {
             socket_closed = 1;
             _parser.flush();            
@@ -354,7 +353,6 @@
             free (data); 
             return -2; 
         }
- //       printf ("--->>>Close flushing recv_amount: %d  \n\r",recv_amount);            
         if(!((_parser.read((char*)data, recv_amount) >0)
             && _parser.recv("OK"))) {
              free (data);
@@ -436,7 +434,7 @@
            cert_type="f_key";                        
         break;
         default:       
-        printf ("Error Unknown certificate type\n\r");
+           printf ("Error Unknown certificate type\n\r");
         return false;
     }
     
@@ -444,7 +442,6 @@
     for (unsigned i = 0; i < 2; i++) {
         if (_parser.send("AT+S.TLSCERT=%s,%d\r%s", cert_type, size, cert)  
             && _parser.recv("OK")) { 
-//            printf ("SET CERT cert_type %s, cert: %s\n\r", cert_type, cert);            
             return true;
         }
         else
@@ -463,7 +460,6 @@
     if (type == FLASH_DOMAIN)
     {
         if (_parser.send("AT+S.TLSDOMAIN=f_domain,%s", domain)) { 
-//            printf ("domain set %s\n\r", domain);
             return true;
         } else {
             printf ("ERROR domain not set \n\r");
@@ -477,17 +473,38 @@
 
 int32_t SPWFSA01::cleanTLScertificate(CertType_t type) 
 {
-    if (type == ALL)
-    {
-        if (_parser.send("AT+S.TLSCERT2=all")) { 
-            return true;
-        } else {
-            printf ("ERROR cleaned \n\r");
-            return false;
-        }
-        
-    } else { 
+    _parser.flush();
+    const char * cert_type="ca";
+    switch (type) {
+        case RAM_CA_ROOT_CERT:
+           cert_type="ca";
+        break;        
+        case RAM_CLIENT_CERT:
+           cert_type="cert";        
+        break;        
+        case RAM_CLIENT_PRIV_KEY:
+           cert_type="key";                
+        break;        
+        case FLASH_CA_ROOT_CERT:
+           cert_type="f_ca";        
+        break;        
+        case FLASH_CLIENT_CERT:
+           cert_type="f_cert";                
+        break;        
+        case FLASH_CLIENT_PRIV_KEY:
+           cert_type="f_key";                        
+        break;
+        case ALL:
+           cert_type="all";
+        break;
+        default:       
+           printf ("Error Unknown certificate type\n\r");
         return false;
-    }
-    
+    }    
+    if (_parser.send("AT+S.TLSCERT2=clean,%s", cert_type) && _parser.recv("OK")) { 
+        return true;
+    } else {
+        printf ("ERROR clean certificate \n\r");
+        return false;
+    }        
 }
\ No newline at end of file