Index: include/freeDiameter/libfdproto.h
===================================================================
--- include/freeDiameter/libfdproto.h	(revision 1422)
+++ include/freeDiameter/libfdproto.h	(revision 1423)
@@ -2367,10 +2367,10 @@
  *
  * PARAMETERS:
- *  msg 	: The message structure in which to search the AVP.
+ *  reference 	: Pointer to a valid msg or avp in which to search the AVP.
  *  what 	: The dictionary model of the AVP to search.
  *  avp		: location where the AVP reference is stored if found.
  *
  * DESCRIPTION:
- *   Search the first top-level AVP of a given model inside a message.
+ *   Search for the first top-level AVP of a given model inside a message or AVP.
  * Note: only the first instance of the AVP is returned by this function.
  * Note: only top-level AVPs are searched, not inside grouped AVPs.
@@ -2382,5 +2382,5 @@
  *  ENOENT	: No AVP has been found, and "avp" was NULL (otherwise, *avp is set to NULL and 0 returned).
  */
-int fd_msg_search_avp ( struct msg * msg, struct dict_object * what, struct avp ** avp );
+int fd_msg_search_avp ( msg_or_avp * reference, struct dict_object * what, struct avp ** avp );
 
 /*
Index: libfdproto/messages.c
===================================================================
--- libfdproto/messages.c	(revision 1405)
+++ libfdproto/messages.c	(revision 1423)
@@ -597,6 +597,6 @@
 }
 
-/* Search a given AVP model in a message */
-int fd_msg_search_avp ( struct msg * msg, struct dict_object * what, struct avp ** avp )
+/* Search a given AVP model in a message or AVP */
+int fd_msg_search_avp ( msg_or_avp * reference, struct dict_object * what, struct avp ** avp )
 {
 	struct avp * nextavp;
@@ -604,13 +604,13 @@
 	enum dict_object_type 	dicttype;
 	
-	TRACE_ENTRY("%p %p %p", msg, what, avp);
-	
-	CHECK_PARAMS( CHECK_MSG(msg) && what );
+	TRACE_ENTRY("%p %p %p", reference, what, avp);
+	
+	CHECK_PARAMS( VALIDATE_OBJ(reference) && what );
 	
 	CHECK_PARAMS( (fd_dict_gettype(what, &dicttype) == 0) && (dicttype == DICT_AVP) );
 	CHECK_FCT(  fd_dict_getval(what, &dictdata)  );
 	
-	/* Loop on all top AVPs */
-	CHECK_FCT(  fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, (void *)&nextavp, NULL)  );
+	/* Loop on all top AVPs in message or AVP */
+	CHECK_FCT(  fd_msg_browse(reference, MSG_BRW_FIRST_CHILD, (void *)&nextavp, NULL)  );
 	while (nextavp) {
 		
@@ -619,5 +619,5 @@
 			break;
 		
-		/* Otherwise move to next AVP in the message */
+		/* Otherwise move to next AVP in the message or AVP */
 		CHECK_FCT( fd_msg_browse(nextavp, MSG_BRW_NEXT, (void *)&nextavp, NULL) );
 	}
Index: tests/testmesg.c
===================================================================
--- tests/testmesg.c	(revision 1414)
+++ tests/testmesg.c	(revision 1423)
@@ -681,4 +681,5 @@
 			struct dict_object * avp_model;
 			struct avp 	   * found;
+			struct avp 	   * grouped = NULL;
 			struct avp_hdr     * avpdata = NULL;
 			
@@ -688,5 +689,9 @@
 			CPYBUF();
 			CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) );
-			
+			CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) );
+#if 0
+			LOG_D("msg: %s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, msg, fd_g_config->cnf_dict, 0, 1));
+#endif
+
 			/* Search this AVP instance in the msg */
 			CHECK( 0, fd_msg_search_avp( msg, avp_model, &found ) );
@@ -695,5 +700,28 @@
 			CHECK( 0, fd_msg_avp_hdr ( found, &avpdata ) );
 			CHECK( 3.1415F, avpdata->avp_value->f32 );
-			
+
+			/* Search for the first grouped message */
+			{
+			struct dict_avp_request grouped_req = { 73565, 0, "AVP Test - grouped"};
+			CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &grouped_req, &avp_model, ENOENT ) );
+			}
+			CHECK( 0, fd_msg_search_avp( msg, avp_model, &grouped ) );
+#if 0
+			LOG_D("grouped: %s", fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, grouped, fd_g_config->cnf_dict, 0, 1));
+#endif
+
+			/* Find the first item in the grouped */
+			{
+			struct dict_avp_request avp_req = { 73565, 0, "AVP Test - os"};
+			CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &avp_req, &avp_model, ENOENT ) );
+			}
+
+			CHECK( 0, fd_msg_search_avp( grouped, avp_model, &found ) );
+
+			/* Check the AVP value is "1" */
+			CHECK( 0, fd_msg_avp_hdr ( found, &avpdata ) );
+			CHECK( 8, avpdata->avp_value->os.len );
+			CHECK( 0, memcmp(avpdata->avp_value->os.data, "12345678", 8));
+
 			/* reinit the msg */
 			CHECK( 0, fd_msg_free ( msg ) );
